0

I have a dataframe where I want to index the first piece of data for that month which for this data is occurring between the 1st and 4th day on each month. My dataframe looks like this with the data continuing for several years:

     Fcst_date Avg_Fcst_Val
0   1999-01-04   607.342708
1   1999-01-08   833.701563
2   1999-01-11  1326.115104
3   1999-01-15  1427.334375
4   1999-01-18  2010.281771

I know you can index a date with mask as I have done here:

mask = (df_avg_fcst_all['Fcst_date'] >= '1999-9-1') & (df_avg_fcst_all['Fcst_date'] <= '1999-9-4')
df_first_day =df_avg_fcst_all.loc[mask]
df_first_day

but I wanted to know if there was a more efficient way to do this as I will also need some type of loop to index for each month

Sefan
  • 700
  • 1
  • 7
  • 22
  • This thread might help you out https://stackoverflow.com/questions/22898824/filtering-pandas-dataframes-on-dates. If you don't mind, could you also state what you plan to do with the indexed data? – PreciXon Aug 26 '21 at 22:41

0 Answers0