here is my problem. I have a DataFrame as follows:
df:
2013-10-24 1
2013-10-25 2
2013-11-27 3
2013-11-28 4
2013-12-01 5
2013-12-02 6
I want the DataFrame to look like this:
roll_mean (df, window = '1M'):
2013-10 1.5
2013-11 3.5
2013-12 5.5
roll_mean (df, window = '2M'):
2013-10 NAN
2013-11 2.5
2013-12 4.5
roll_mean (df, window = '3M'):
2013-10 NAN
2013-11 NAN
2013-12 3.5
roll_mean (df, window = '1Y'):
2013-10 NAN
2013-11 NAN
2013-12 NAN
where 1M is "1 month", 2M is "2 months". The window is not an int value, but a time interval such as "1D", "3M", "1Y", etc. This function can be grouped using a data block using a unit of time, such as "D", "M", "Y", and then rolling the data frame through a number to a unit of time, such as 1, 3 ...
Do I need a rolling function like this? Can anyone help me out? Did I give a clear description? Many thanks.
Update:
.
, , , .
,
, ,
:
2013-10-24 1
2013-10-25 2
2013-11-27 3
2013-11-28 4
2013-12-01 5
2013-12-02 6
pd.rolling_std (df.resample( '1 '), = 1):
2013-10 NAN
2013-11 NAN
2013-12 NAN
, dataframe, (window = 1):
2013-10 0.5
2013-11 0.5
2013-12 0.5
0.5 - , np.sqrt([1,2]) .
0,5 [3,4] [5,6].
, how = 'xxx' resample, .
2 ,
df (window = 2):
2013-10 NAN
2013-11 1.1180
2013-12 1.1180
1.1180 - , np.sqrt([1,2,3,4]) .
1.1180 2013-12 [3,4,5,6] 2013-11 2013-12 .
p.s.
- , ...
~