python getmax函数_Python pandas.DataFrame.cummax函数方法的使用

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值