获取pandas数据帧中的最大值

j. *_*DOE 0 time-series dataframe python-3.x pandas

我想在Pandas Dataframe中创建一个新列,其中包含截至此时间点的另一列的最大值.
例如:

time  | value | max value   
 1        2        2  
 2        4        4  
 3        3        4  
 4        3        4 
 5        6        6
Run Code Online (Sandbox Code Playgroud)

有人知道如何为"最大值"列创建代码吗?
谢谢

Sco*_*ton 5

用途cummax:

df['max value'] = df['value'].cummax()
Run Code Online (Sandbox Code Playgroud)

输出:

   time  value  max value
0     1      2          2
1     2      4          4
2     3      3          4
3     4      3          4
4     5      6          6
Run Code Online (Sandbox Code Playgroud)