0

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))]
FObersteiner
  • 22,500
  • 8
  • 42
  • 72

1 Answers1

1

you have a few options:

  1. 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()
  1. DataFrame.last_valid_index()
df[df.last_valid_index()-pandas.DateOffset(30, 'D'):]
FObersteiner
  • 22,500
  • 8
  • 42
  • 72
Tal Folkman
  • 2,368
  • 1
  • 7
  • 21