I am trying to filter a Pandas df by dates (today and yesterday). For automation purposes I wish to filter using a timestamp function. This is pretty seamless in R:
df %>%
filter(date >= today() - 1)
However, my attempts to replicate in Pandas are not reaching any success so far: Yesterday comes out fine, but .query() doesnt recognise it?
yesterday = (date.today() - timedelta(days=6)).strftime('%Y-%m-%d')
df.\
query('date >= yesterday')
Ideally I am seeking something all encompassing like:
df.\
query('date >= (date.today() - timedelta(days=6)).strftime('%Y-%m-%d')')
timedelta(days=6)(six days ago) in Python and comparing against grabbing yesterday (one day ago) in R?