pyspark.pandas.groupby.GroupBy.idxmax

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

返回组中沿请求轴的最大值的首次出现的索引。 NA/null 值被排除。

Parameters
skipna boolean, default True

排除NA/null值。如果整行/整列都是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