如何计算每天52周的熊猫高/低?
我有一个具有典型OHLC值的简单数据框.我想从中计算每天52周的高/低(或其他时间范围),并将结果放入数据框,以便我可以跟踪所有记录的高/低的每日走势.
I have a simple dataframe with typical OHLC values. I want to calculate daily 52 weeks high/low (or other time range) from it and put the result into a dataframe, so that I can track the daily movement of all record high/low.
例如,如果时间范围仅为3天,则3天的高/低将为: (三天最高价:最近三天的最高最高价")
For example, if the time range is just 3-day, the 3-day high/low would be: (3-Day High: Maximum 'High' value in the last 3 days)
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
有什么简单的方法可以做到吗?谢谢大家!
Is there any simple way to do it and how? Thanks guys!
上述方法已在最新版本的python中替换. 改用这个: Series.rolling(min_periods = 1,window = 252,center = False).max()
The above method has been replaced in the latest versions of the python Use this instead: Series.rolling(min_periods=1, window=252, center=False).max()