Python Pandas: 如何分组统计和select一部分统计?

Python Pandas: How to groupby and count and select a portion of counts?

我有一个这样的 df:

          new_org               old_org    asn  cc
0    85736 pcizzi   85736 - Pcizzi S .a  23201  PY
1             001              001 Host  40244  US
2      85736 blah       85736 - whatevs  23201  PY
3             001        001 IT Complex  55734  IN
4  001 hospedagem   001 Hospedagem Ltda  36351  US
5          001web  action.us.001web.net  36351  US

我想根据 'asn' 列和 select 那些有多于一行的组对我的 df 进行分组。我现在就是这样做的,但我不确定它是否正确:

df.groupby('asn').apply(lambda x:x.count()>1)

有人可以帮忙吗?

你可以filter a group.

尝试 df.groupby('asn').filter(lambda x: len(x) > 1),这将 return 你 DataFrame。如有必要,您可以将其进一步分组。