Pandas: Filter Results Based on Date (which is an Index)

Hello Community,

I have a problem with applying conditions based on the period (e.g. show results only for the last month) using “Date” which is an index in the used dataframe.

Basically, we have the following parameters:

today = dt.datetime.now()
bdate_output = today - dt.timedelta(30) # Get results for the last 30 days

Based on the parameters above, a filter is defined. The idea of the filter is to exclude results older than “Today - 30 days”.

filtdate = df.loc[bdate_output:today]

Printing the dataframe results raises an “ValueError: Boolean array expected for the condition, not object” type of error.

print(df[filtdate])

Could you please help me to understand what is the problem and to properly filter the results output based on “Date” ?