我想忽略行,因为职业的唯一名称少于2个:
name value occupation
a 23 mechanic
a 24 mechanic
b 30 mechanic
c 40 mechanic
c 41 mechanic
d 30 doctor
d 20 doctor
e 70 plumber
e 71 plumber
f 30 plumber
g 50 tailor
我做到了:
df.groupby('ocuupation')['name'].nunique()
>>>>>>
occupation
mechanic 3
doctor 1
plumber 2
tailor 1
Name: name, dtype: int64
可以使用类似df = df.drop(df[<some boolean condition>].index)
的东西吗
期望输出:
name value occupation
a 23 mechanic
a 24 mechanic
b 30 mechanic
c 40 mechanic
c 41 mechanic
e 70 plumber
e 71 plumber
f 30 plumber
使用^{} 和^{} 来获取大于等于
2
的值:您的解决方案是对^{} 中比较的串联索引值进行过滤:
相关问题 更多 >
编程相关推荐