This seems like it should be easy but I can find no answer when googling. Say I have some variable k that is of type pandas.Period, and whose value is:
Period('2018-11', 'M')
How do I add n months to this variable. For example if n is 3 i would want k to be
Period('2019-02', 'M')
I have tried the following:
k.month = k.month + 12
But this fails saying:
AttributeError: attribute 'month' of 'pandas._libs.tslibs.period._Period' objects is not writable
Add a pd.offsets
.MonthEnd
object:
pd.Period('2018-11', 'M') + pd.offsets.MonthEnd(3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With