我有一个比赛结果的数据框,我试图看看比赛的获胜者是否来自与比赛相同的位置。熊猫 - 无法获得Series.isin的工作
round_loc柱:
0 Val d'Allos, France
168 Les Deux Alpes, France
378 Winter Park, CO, USA
499 Whistler, BC, Canada
...
国家列:
0 France
168 France
378 France
499 Australia
602 France
...
我的代码:
winners_df = df.loc[df['finish_position'] == 1, ['country', 'round_loc']]
hometown_win = winners_df['country'].isin(winners_df['round_loc'])
# Also tried
hometown_win = winners_df['country'].isin(winners_df['round_loc'].values)
print(hometown_win)
我的结果:
0 False
168 False
378 False
499 False
602 False
...
不知道我在做什么错。
winners_df['country'][0] in winners_df['round_loc'][0]
工作正常。我确信我可以用循环做,但我觉得我在这里错过了一些东西。
这不行'isin'正在寻找完全匹配,你想比较每一行并使用'contains'来测试这里的会员资格/匹配 – EdChum