pandas.DataFrame.cummax#

DataFrame.cummax(axis=None, skipna=True, *args, **kwargs)[源代码]#

返回 DataFrame 或 Series 轴上的累积最大值。

返回一个大小相同、包含累积最大值的DataFrame或Series。

Parameters:
axis{0 或 ‘index’, 1 或 ‘columns’}, default 0

轴的索引或名称。0 等价于 None 或 ‘index’。对于 Series,此参数未使用,默认为 0。

<strong>skipna</strong>bool, default True

排除 NA/null 值。如果整行/整列都是 NA,则结果为 NA。

*args, **kwargs

附加关键字不起作用,但为了兼容 NumPy 可能仍然被接受。

Returns:
Series 或 DataFrame

返回Series或DataFrame的累积最大值。

参见

core.window.expanding.Expanding.max

功能类似,但会忽略 NaN 值。

DataFrame.max

返回DataFrame轴上的最大值。

DataFrame.cummax

返回DataFrame轴上的累积最大值。

DataFrame.cummin

返回DataFrame轴上的累积最小值。

DataFrame.cumsum

返回DataFrame轴上的累积和。

DataFrame.cumprod

返回DataFrame轴上的累积积。

Examples

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=Noneaxis='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