I have observed that, pandas' offsets.YearEnd
is returning next year if input date is year end. Below is one such example
import pandas as pd
pd.to_datetime('2000-12-31') pd.offsets.YearEnd() ## Timestamp('2001-12-31 00:00:00')
Is it expected behaviour? How can I force to have same year if actual date itself is year-end?
CodePudding user response:
You can explicitly specify the offset as 0
which will make sure that the calendar year does not gets incremented, See the below example,
>>> pd.to_datetime('2000-12-31') pd.offsets.YearEnd(0)
Timestamp('2000-12-31 00:00:00')
>>> pd.to_datetime('2000-06-02') pd.offsets.YearEnd(0)
Timestamp('2000-12-31 00:00:00')