Josh Josh - 8 months ago 52
Python Question

filter pandas dataframe for past x days

I have a dataframe with a date column that I update daily. I'd like to create a copy of it with just the past 30 day's of data.

I tried the following syntax based on what I know about doing this in R:


The date column is not the index but I'm not opposed to making it so if that helps!



Try this:

import datetime
import pandas as pd 

df[ > - pd.to_timedelta("30day")]