Tom*_*eck 0 python pandas pandas-groupby
有没有一种简单的方法可以通过调用返回具有最多行的组df.groupby(..)?
# Return group most rows e.g.
largest_group = df.groupby("community_area").max()
Run Code Online (Sandbox Code Playgroud)
max 带有返回形状的键函数
>>> df
one two
a 1.0 1.0
b 2.0 2.0
c 3.0 3.0
d 2.0 4.0
e 2.0 5.0
>>> gb = df.groupby('one')
>>> key,grp = max(gb,key=lambda x: x[1].shape)
>>> grp
one two
b 2.0 2.0
d 2.0 4.0
e 2.0 5.0
>>>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
578 次 |
| 最近记录: |