【发布时间】:2018-11-25 20:06:13
【问题描述】:
您好,我想删除出现次数小于数字的条目的行,例如:
df = pd.DataFrame({'a': [1,2,3,2], 'b':[4,5,6,7], 'c':[0,1,3,2]})
df
a b c
0 1 4 0
1 2 5 1
2 3 6 3
3 2 7 2
如果“a”列中出现的次数少于两次,我想删除所有行。
想要的输出:
a b c
1 2 5 1
3 2 7 2
我知道的:
我们可以通过condition = df['a'].value_counts() < 2 找到出现次数,它会给我如下信息:
2 False
3 True
1 True
Name: a, dtype: int64
但我不知道应该如何从这里删除行。
提前致谢!
【问题讨论】:
标签: python pandas dataframe counter pandas-groupby