2014-09-22 14 views
0

我有一個有三列ID,日期,值的熊貓數據框。pandas rolling_min和rolling_max不同的行爲?

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 

我想計算這些值的符號分組的最大值和最小值。對於滾動最大

df.groupby('symbol')['PX_HIGH'].apply(lambda x: pd.rolling_max(x,window=20,min_periods=20) 

我也得到

Out[418]: 
0 NaN 
... 
83605  54.5400 
83606  56.0500 
Length: 83620, dtype: float64 

然而,當我使用滾動分鐘

df.groupby('symbol')['PX_HIGH'].apply(lambda x: pd.rolling_min(x,window=20,min_periods=20) 

我得到

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) 

任何理由爲什麼做samething這可能是?我使用的是熊貓0.13.1

+0

這看起來很奇怪,不知道那裏發生了什麼,但你可能想更新到最新的穩定熊貓(14.1),看看是否能解決這個問題。 – JohnE 2014-09-22 16:11:09

+0

謝謝,我會給它一個鏡頭。 – Mishiko 2014-09-22 17:46:12

回答

相關問題