I have a pandas data frame with three columns id,date,value.
Out[411]:
symbol date_col PX_HIGH
0 BF/B US Equity 2014-01-02 75.6800
1 DLTR US Equity 2014-01-02 56.5600
2 EMN US Equity 2014-01-02 80.5300
83620 rows × 3 columns
I would like to compute the rolling max and min on these values grouping by symbol. For rolling max
df.groupby('symbol')['PX_HIGH'].apply(lambda x: pd.rolling_max(x,window=20,min_periods=20)
And I get
Out[418]:
0 NaN
...
83605 54.5400
83606 56.0500
Length: 83620, dtype: float64
However, when I do the samething using rolling min
df.groupby('symbol')['PX_HIGH'].apply(lambda x: pd.rolling_min(x,window=20,min_periods=20)
I get
ValueError Traceback (most recent call last)
<ipython-input-419-030ef09b7d35> in <module>()
1
----> 2 update_df.groupby('symbol')['PX_HIGH'].apply(lambda x: pd.rolling_min(x,20,20))
...
ValueError: min_periods (20) must be <= window (17)
Any reason for why this might be? I'm using pandas 0.13.1
我不确定为什么pd.rolling_max()
不能工作,但pd.rolling_min()
不能工作,但我认为此问题已在Pandas pd.rolling_min()
中修复-请参阅http://pandas.pydata.org/下的第一项pandas-docs / version / 0.15.0 / whatsnew.html#whatsnew-0150-roll ( https://github.com/pydata/pandas/pull/7766 )。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.