How to resample 6 months in pandas? For example, I have 2 dates '2018-02-07'
and '2018-09-17'
. I want to resample them in 6 month period, the result should be '2018-06-30'
and '2018-12-31'
.
I setup the code below:
import pandas as pd
import numpy as np
series = pd.Series([1,2], index=[pd.Timestamp('2018-02-07'), pd.Timestamp('2018-09-17')])
s.resample('6M').sum()
It gives '2018-02-28'
, '2018-08-31'
, '2019-02-28'
, but this is not what I want.
I think this can help your purposes:
> series.resample('2Q', closed='left').last()
2018-06-30 1
2018-12-31 2
Freq: 2Q-DEC, dtype: int64
Just resampling every 2 Quarters, but closing the interval to the 'left' and getting the last value we have for each semester. More info about the aliases in pandas in the documentation.
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