计算pandas中一系列的运行(累积)最大值

时间:2016-09-14 20:01:07

标签: python pandas dataframe series

假设:

d = {
    'High': [954,
             953,
             952,
             955,
             956,
             952,
             951,
             950,
            ]
}
df = pandas.DataFrame(d)

我想添加另一列,它是从头开始的每个索引的最大值。例如,所需的列将是:

'Max': [954, 
        954, 
        954, 
        955, 
        956, 
        956, 
        956, 
        956]

我试过一个pandas滚动功能,但窗口似乎不是动态的

1 个答案:

答案 0 :(得分:5)

使用startFormat: ["AVSampleRateKey": 16000, "AVLinearPCMBitDepthKey": 32, "AVLinearPCMIsFloatKey": 1, "AVNumberOfChannelsKey": 2, "AVFormatIDKey": 1819304813, "AVLinearPCMIsNonInterleaved": 0, "AVLinearPCMIsBigEndianKey": 0] endFormatSettings: ["AVSampleRateKey": 16000, "AVLinearPCMBitDepthKey": 16, "AVLinearPCMIsFloatKey": 1, "AVNumberOfChannelsKey": 1, "AVFormatIDKey": 1819304813, "AVLinearPCMIsNonInterleaved": 0, "AVLinearPCMIsBigEndianKey": 0, "AVEncoderQualityKey": 64] avconverterError: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)"

cummax
df.High.cummax()

0    954
1    954
2    954
3    955
4    956
5    956
6    956
7    956
Name: High, dtype: int64

enter image description here