当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python pyspark GroupBy.idxmax用法及代码示例


本文简要介绍 pyspark.pandas.groupby.GroupBy.idxmax 的用法。

用法:

GroupBy.idxmax(skipna: bool = True) → FrameLike

返回组中请求轴上第一次出现最大值的索引。 NA/空值被排除在外。

参数

skipna布尔值,默认 True

排除 NA/空值。如果整行/列为 NA,则结果将为 NA。

例子

>>> df = ps.DataFrame({'a': [1, 1, 2, 2, 3],
...                    'b': [1, 2, 3, 4, 5],
...                    'c': [5, 4, 3, 2, 1]}, columns=['a', 'b', 'c'])
>>> df.groupby(['a'])['b'].idxmax().sort_index() 
a
1  1
2  3
3  4
Name: b, dtype: int64
>>> df.groupby(['a']).idxmax().sort_index() 
   b  c
a
1  1  0
2  3  2
3  4  4

相关用法


注:本文由纯净天空筛选整理自spark.apache.org大神的英文原创作品 pyspark.pandas.groupby.GroupBy.idxmax。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。