## 如何计算熊猫每天52周高/低？内容来源于 Stack Overflow，并遵循CC BY-SA 3.0许可协议进行翻译与使用

• 回答 (2)
• 关注 (0)
• 查看 (4)

``````Out[21]:
Open   High    Low  Close    Volume  3-Day-High 3-Day-Low
Date
2015-07-01  273.6  273.6  273.6  273.6         0       273.6     273.6
2015-07-02  276.0  276.0  267.0  268.6  15808300       276.0     267.0
2015-07-03  268.8  269.0  256.6  259.8  20255200       276.0     256.6
2015-07-06  261.0  261.8  223.0  235.0  53285100       276.0     223.0
2015-07-07  237.2  237.8  218.4  222.0  38001700       269.0     218.4
2015-07-08  207.0  219.4  196.0  203.4  48558100       261.8     196.0
2015-07-09  207.4  233.8  204.2  233.6  37835900       237.8     196.0
2015-07-10  235.4  244.8  233.8  239.2  23299900       244.8     196.0
``````

### 2 个回答

``````three_days=df.index[-3:]
maxHigh=max(df['High'][three_days])
minLow=min(df['Low'][three_days])
``````

``````>>> df["3-Day-High"] = pd.rolling_max(df.High, window=3, min_periods=1)
>>> df["3-Day-Low"] = pd.rolling_min(df.Low, window=3, min_periods=1)
>>> df
Open   High    Low  Close    Volume  3-Day-High  3-Day-Low
Date
2015-07-01  273.6  273.6  273.6  273.6         0       273.6      273.6
2015-07-02  276.0  276.0  267.0  268.6  15808300       276.0      267.0
2015-07-03  268.8  269.0  256.6  259.8  20255200       276.0      256.6
2015-07-06  261.0  261.8  223.0  235.0  53285100       276.0      223.0
2015-07-07  237.2  237.8  218.4  222.0  38001700       269.0      218.4
2015-07-08  207.0  219.4  196.0  203.4  48558100       261.8      196.0
2015-07-09  207.4  233.8  204.2  233.6  37835900       237.8      196.0
2015-07-10  235.4  244.8  233.8  239.2  23299900       244.8      196.0
``````