DataFrame.cummax(axis=None, skipna=True, *args, **kwargs)
返回一个DataFrame或Series轴上的累积最大值。
返回包含累积最大值的相同大小的DataFrame或Series。
参数: | axis : {0 或 ‘index’, 1 或 ‘columns’}, 默认 0 索引或轴的名称。0等于None或' index '。 skipna : boolean, 默认 True 排除NA/null值。如果整个行/列是NA,那么结果将是NA。 *args, **kwargs : 附加关键字没有效果,但是可以接受与NumPy兼容。 |
返回: | cummax : Series 或 DataFrame |
例子,
Series
>>> s = pd.Series([2, np.nan, 5, -1, 0])
>>> s
0 2.0
1 NaN
2 5.0
3 -1.0
4 0.0
dtype: float64
默认情况下,NA值被忽略
>>> s.cummax()
0 2.0
1 NaN
2 5.0
3 5.0
4 5.0
dtype: float64
若要在操作中包含NA值,请使用skipna=False
>>> s.cummax(skipna=False)
0 2.0
1 NaN
2 NaN
3 NaN
4 NaN
dtype: float64
DataFrame
>>> df = pd.DataFrame([[2.0, 1.0],
... [3.0, np.nan],
... [1.0, 0.0]],
... columns=list('AB'))
>>> df
A B
0 2.0 1.0
1 3.0 NaN
2 1.0 0.0
默认情况下,遍历行并在每一列中找到最大值。这相当于axis=None或axis='index'
>>> df.cummax()
A B
0 2.0 1.0
1 3.0 NaN
2 3.0 1.0
若要遍历列并找到每行中的最大值,请使用axis=1
>>> df.cummax(axis=1)
A B
0 2.0 2.0
1 3.0 NaN
2 1.0 1.0