How to find one day previous and one day after for given date which are comma separated or given in range in Pandas df

Viewed 39
import pandas as pd
import numpy as np

df = pd.DataFrame({         
      'dates': [ '10-Mar-22,9-Apr-22', '5-Jan-22 to 1-Mar-22,10-Mar-22 to 7-May-22']})
    dates

0   10-Mar-22,9-Apr-22

1   5-Jan-22 to 1-Mar-22,10-Mar-22 to 7-May-22

required output for row 1 Previous day1 next day1 previous day2 next day2 (there are multiple dates in the column Restricted dates)

  dates                       PD1          ND1      PD2       ND2

0   10-Mar-22,9-Apr-22           09-Mar-22   1-Mar-22  8-Apr-22   10-Apr-22

1   5-Jan-22 to 1-Mar-22,      4-Jan-22    2-Mar-22    9-mar-22    8-may-22

10-Mar-22 to 7-May-22

required output for row 2

to understand row 2 better i am explaining here

Input:5-Jan-22 to 1-Mar-22,10-Mar-22 to 7-May-22

PD1:4-Jan-22, ND1: 2-Mar-22,PD2: 9-Mar-22,ND2: 8-May-22

There could be multiple date range(contain multiple to)

0 Answers
Related