Pandas Filter dataframe according to working days

  dataframe, datetime, filter, pandas, python

I want to filter a df with respect to working days.The df is:

name     date
aaa    12/06/2021
bbb    11/06/2021
ccc    10/06/2021
zzz    15/06/2021
ddd    13/06/2021
eee    10/05/2021
fff    01/06/2021
ggg    10/05/2021
hhh    13/06/2021
iii    14/06/2021
nnn    15/06/2021
jjj    15/06/2021

Now for everday process i want all the rows before two working days that means 13/06/2021 will not be included as it was a Sunday.I used

new_date = dt.date.today()-pd.Timedelta(2, unit='d')
new_date = pd.to_datetime(new_date)
new_df = df[df['date'] < new_date]

Output should be

name     date
aaa    12/06/2021
bbb    11/06/2021
ccc    10/06/2021
eee    10/05/2021
fff    01/06/2021
ggg    10/05/2021

but it is giving me sunday also ie 13/06/2021.Can anyone help me out here please

Source: Python Questions

LEAVE A COMMENT