I have filtered the datetime64[ns]
type in pandas dataframe to get data that falls on specific date of each month using the following line of code.
df[df['Date'].map(lambda x: x.day) == 1]
The output is as follows:
19.9 2013-07-01
34.8 2013-08-01
12.9 2013-10-01
12.6 2013-11-01
But if you notice the entry for 2013-09-01
is missing as it is not available in the original dataset. In such situation I want to get data for 2013-09-02
. Ideally if a date falls on weekend (Saturday and Sunday or any missing date like holidays or data not available for specific date), I want to get the data for the next available date. Wondering if we can achieve using pandas or I need to manually iterate over perform this functionality.
I think you need
DatetimeIndex
withasfreq
andmethod='bfill'
for back filling missing values:Then filter by
DatetimeIndex.day
:Sample: