I would like to filter my dataframe so that I get only the rows with the latest 2 days of data (relative to the latest available date from the dataframe). So this code would work:
df[pd.to_datetime(df['date']) <= pd.to_datetime(df['date'].max()) - pd.to_timedelta('2 days')]
But now I would like to achieve this same effect but using the query
method. But if I do this:
df.query("@pd.to_datetime(quote_date) <= @pd.to_datetime(quote_date.max()) - @pd.to_timedelta('2 days')")
then I get TypeError: Cannot convert input [2 days 00:00:00] of type <class 'pandas._libs.tslibs.timedeltas.Timedelta'> to Timestamp
error.
I can't get this thing to work, and would love to get some feedbacks on what I'm doing wrong.