Reputation: 35
I'm trying to get 30 days records from the table.
df['Form Modified Date']=pd.to_datetime(df['Form Modified Date'].astype(str), format='%Y/%m/%d')
#print (df)
timenow = str(datetime.now().strftime("%Y-%m-%d")) - 30 days
nya= df[(df['Form Modified Date'] == (timenow))]
Upvotes: 0
Views: 367
Reputation: 2571
you have a few options:
df.loc
dayfrom = pd.to_datetime('1/23/2020')
#set index from column Date
df = df.set_index('Date')
df= df.sort_index()
#last 30 days of date lastday
df = df.loc[dayfrom - pd.Timedelta(days=30):dayfrom].reset_index()
DataFrame.last_valid_index()
df[df.last_valid_index()-pandas.DateOffset(30, 'D'):]
Upvotes: 1