I have a dataframe, df with 2 columns, ‘years’ and ‘count’. The ‘years’ column contains datetime values, and the ‘count’ column contains integers.
years count
0 2000-09-06 1
1 2157-11-16 1
When trying to group it by years using pd.Grouper as below
df = df.groupby([pd.Grouper(freq='100YS',key='years')])
the OutOfBoundsDatetime error is encountered.
pandas._libs.tslibs.np_datetime.OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 2300-01-01 00:00:00
I understand that with freq = ‘100YS’, the years are tried to group as 2000,2100,2200 etc.
Is there any way to prevent this error by passing in a max date value or any other approach to obtain the same result
For freq = ’50YS’, the expected result is obtained when performing df['count'].sum()
years
2000-01-01 1
2050-01-01 0
2100-01-01 0
2150-01-01 1
Karen Joseph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.