我有一个数据框,我想比较它们是否存在于另一个 df 中。after_h.sample(10, random_state=1) movie year ratings108 Mechanic: Resurrection 2016 4.0206 Warcraft 2016 4.0106 Max Steel 2016 3.5107 Me Before You 2016 4.5我想比较上述电影是否存在于另一个 df 中。 FILM Votes0 Avengers: Age of Ultron (2015) 41701 Cinderella (2015) 9502 Ant-Man (2015) 3000 3 Do You Believe? (2015) 3504 Max Steel (2016) 560 我想要这样的东西作为我的最终输出: FILM votes0 Max Steel 560
3 回答

慕婉清6462132
TA贡献1804条经验 获得超2个赞
给定输入数据帧df1和df2,您可以通过 使用布尔索引pd.Series.isin。要对齐电影字符串的格式,您需要首先连接电影和年份df1:
s = df1['movie'] + ' (' + df1['year'].astype(str) + ')'
res = df2[df2['FILM'].isin(s)]
print(res)
FILM VOTES
4 Max Steel (2016) 560
添加回答
举报
0/150
提交
取消