【问题标题】:Python Pandas: How to groupby and count and select a portion of counts?Python Pandas:如何分组和计数并选择部分计数?
【发布时间】:2015-07-27 02:57:36
【问题描述】:

我有一个这样的 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”列对我的 df 进行分组,并选择那些具有多于一行的组。这就是我现在的做法,但我不确定它是否正确:

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

有人可以帮忙吗?

【问题讨论】:

    标签: python pandas count group-by


    【解决方案1】:

    你可以filter a group

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      • 1970-01-01
      • 2020-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多