I have a df of data. I need to be able to return certain rows of the data based on the day of the week.
If its monday I need to print the rows which contain data for the past 3 days. If its wednesday or friday I need to print the rows which contain the data for the past two days.
Merging two df to create one:
df_new = pd.concat([outcomes_df, specialists_df], ignore_index=True)
df_new['Published Date'] = pd.to_datetime(df_new['Published Date'])
Getting the correct dates based today's date:
N=0
if datetime.today().weekday() == 0:
N = 3
elif datetime.today().weekday() == 2 or datetime.today().weekday() == 4:
N = 2
else:
pass
mydate = datetime.now() - timedelta(days=N)
print(mydate)
Filtering by the date range
df_new = df_new[(df_new['Published Date'] >= mydate) & (df_new['Published Date'] <= datetime.today())]
print(mydate)
results in the correct date
print(df_new)
results in error:
Empty DataFrame Columns: [col1, col2, col3, Published Date] Index: []