Let's say that I have the following dataframe:
dates,qq
1900-01-01,1
1900-01-02,2
1900-01-03,3
1900-01-04,4
1900-01-05,5
1900-01-06,6
1900-01-07,7
1901-01-01,8
1901-01-02,9
1901-01-03,10
1901-01-04,11
1901-01-05,12
1901-01-06,13
1901-01-07,14
1902-01-01,15
1902-01-02,16
1902-01-03,17
1902-01-04,18
1902-01-05,19
1902-01-06,20
1902-01-07,21
1903-12-30,22
1903-12-31,23
Firstly, I have read the dataframe as:
dfr = pd.read_csv('test.csv', sep=',',index_col=0,parse_dates=True)
Now I would like selected all the values around a specific day of the year but independently from the year.
Let's say that I have selected the first of January and a +- delta of 2 days:
delta_d = pd.Timedelta(2., unit='d')
dates = pd.date_range(start='1/1/1400', end='1/1/1401')
day_c = dates[0]
A good idea could be to create a mask. I have tried the following:
mask = (dfr.index.day>= day_c.day) & (dfr.index.day < day_c.day+delta_d)
However, as I could have expected, I get the following error:
OutOfBoundsDatetime: Cannot cast 1400-01-01 00:00:00 to unit='ns' without overflow.
I expect the following result:
res = [1,2,3,8,9,10,15,16,17,22,23]