I have this data:
df = pd.DataFrame({Period('2017-01-01', 'D'): 319.8333333333333,
Period('2017-01-02', 'D'): 241.20833333333334,
Period('2017-01-03', 'D'): 226.75,
Period('2017-01-04', 'D'): 217.60416666666666,
Period('2017-01-05', 'D'): 204.0625})
I'm trying to subtract one year from the period index. I have tried these 1,2 solutions:
df.index + pd.offsets.MonthEnd(12)
But none of them worked as it gave me these error:
IncompatibleFrequency: Input has different freq=12M from PeriodArray(freq=D)
IncompatibleFrequency: Input has different freq=<DateOffset: years=1> from PeriodArray(freq=D)
The only solution I have found is to transform the Period format to another time format (timestamp, datetime, etc.) and then add the year. However, this approach decreases significantly the code's readability and I feel it's an inefficient approach (as I would have to convert to Period format again once the year is subtracted). Hopefully, I'm looking for a straight answer like:
df.index - some_functions(year=1)
If that's impossible, could be using an additional column and then dropping it, but I'm trying to avoid using another time format.
PS: Be aware that adding 365 days for a year can't be the solution as I'm working with multiple years (and not every year has 365 days).