我有一个数据框,如下所示:df:Noun Thumb_count ability 19.0account 3.0accuracy 155.0accurate 151.0activity 163.0adapt 3.0app 15.0gps 13.0我有另一个数据框,如下所示:df1:Review Text Noun Thumbups Rating Review DateThis app is not working properly. GPS is showi... app 34.0 2 August 3, 2020This app is not working properly. GPS is showi... gps 34.0 2 August 3, 2020This app is not working properly. GPS is showi... network 34.0 2 August 3, 2020This app is not working properly. GPS is showi... connectivity 34.0 2 August 3, 2020This app is not working properly. GPS is showi... signal 34.0 2 August 3, 2020现在我想保留 df1 的唯一行,其中 df1 的名词列与 df 的名词列具有相同的值。这是我的过滤代码:df1[df1.Noun.str.contains(('|').join(df.Noun.values.tolist()))]当我运行上面的命令时,它抛出以下错误:error: nothing to repeat at position 2我不确定我在哪里犯了错误。谁能指导我哪里做错了?
1 回答

人到中年有点甜
TA贡献1895条经验 获得超7个赞
我想你添加了一个额外的括号,试试:
df1[df1.Noun.str.contains('|'.join(df.Noun.tolist()))]
您可以使用isin
方法:
df1[df1.Noun.isin(df.Noun)]
添加回答
举报
0/150
提交
取消