我有一個數(shù)據(jù)框,如下所示:df:Noun Thumb_count ability 19.0account 3.0accuracy 155.0accurate 151.0activity 163.0adapt 3.0app 15.0gps 13.0我有另一個數(shù)據(jù)框,如下所示: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現(xiàn)在我想保留 df1 的唯一行,其中 df1 的名詞列與 df 的名詞列具有相同的值。這是我的過濾代碼:df1[df1.Noun.str.contains(('|').join(df.Noun.values.tolist()))]當我運行上面的命令時,它拋出以下錯誤:error: nothing to repeat at position 2我不確定我在哪里犯了錯誤。誰能指導我哪里做錯了?
1 回答

人到中年有點甜
TA貢獻1895條經(jīng)驗 獲得超7個贊
我想你添加了一個額外的括號,試試:
df1[df1.Noun.str.contains('|'.join(df.Noun.tolist()))]
您可以使用isin
方法:
df1[df1.Noun.isin(df.Noun)]
添加回答
舉報
0/150
提交
取消