Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从dataframe中删除值在整个列中仅出现一次的行_Python_Dataframe - Fatal编程技术网

Python 从dataframe中删除值在整个列中仅出现一次的行

Python 从dataframe中删除值在整个列中仅出现一次的行,python,dataframe,Python,Dataframe,我有这样一个数据框: import pandas as pd data = [['bob', 1], ['james', 4], ['joe', 4], ['joe', 1], ['bob', 3], ['wendy', 5], ['joe', 7]] df = pd.DataFrame(data, columns=['name', 'score']) print(df) 看起来像: name score 0 bob 1 1 james 4 2 j

我有这样一个数据框:

import pandas as pd

data = [['bob', 1], ['james', 4], ['joe', 4], ['joe', 1], ['bob', 3], ['wendy', 5], ['joe', 7]]
df = pd.DataFrame(data, columns=['name', 'score'])
print(df)
看起来像:

    name  score
0    bob      1
1  james      4
2    joe      4
3    joe      1
4    bob      3
5  wendy      5
6    joe      7
我想以一种类似蟒蛇的方式删除所有只出现一次的人,即结果应如下所示:

    name  score
0    bob      1
2    joe      4
3    joe      1
4    bob      3
6    joe      7
。。。对于只出现1次或2次的条目,我该如何处理?i、 e

    name  score
2    joe      4
3    joe      1
6    joe      7
尝试此操作,以获取每个组中唯一元素的计数,并应用
isin
筛选出现的元素

g = df.groupby(['name'])['score'].transform('nunique')



请共享您尝试过的代码
df[~g.isin([1])]

  name  score
0  bob      1
2  joe      4
3  joe      1
4  bob      3
6  joe      7
df[~g.isin([1,2])]

  name  score
2  joe      4
3  joe      1
6  joe      7