我将数据读入DataFrame并将其称为数据。我在python中有以下查询:
data[data["gender"]=="male"].groupby('age').city.nunique().sort_values(ascending=False)
age
29 86
24 85
21 81
25 81
20 81
28 78
27 78
现在我想找到那些大小超过80的组。我怎么能在python中做到这一点?
答案 0 :(得分:0)
汇总和排序调用的结果是一个pandas系列,其索引是您要查找的组。因此,要查找具有大于某个cutOffvalue
cutOffValue = 80
counts = data[data["gender"]=="male"].groupby('age').city.nunique().sort_values(ascending=False)
groups = counts[counts > cutOffValue].index
当然,如果您想将它作为列表或集合,您可以轻松地转换最终值
groups = list(groups)