I have a dataframe of race results and I am trying to see if the winner of the race is from the same location as the race.
round_loc column:
0 Val d'Allos, France 168 Les Deux Alpes, France 378 Winter Park, CO, USA 499 Whistler, BC, Canada ... country column:
0 France 168 France 378 France 499 Australia 602 France ... My Code:
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) My results:
0 False 168 False 378 False 499 False 602 False ... Not sure what I'm doing wrong.
winners_df['country'][0] in winners_df['round_loc'][0] Works fine. I'm sure I could just do it with a loop but I feel like I'm missing something here.
isinis looking for exact matches, you want to compare each row and usecontainsto test for membership/matches here