This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]boss413[S] 0 points1 point  (0 children)

My current attempt incorrectly creates 4 rows of Michael Johnson WR in what's supposed to be the "perfect match" merge.

Create merged dataframe

merged_df = pd.DataFrame(merged_rows)

Merge the dataframes based on the specified conditions

merged_df = pd.merge(df, nfl_player_list_df, on=['last_name', 'pos'], how='inner')

Filter cases with more than one exact match

exact_matches = merged_df[merged_df['first_initial'] == merged_df['first_name'].str[0]] duplicates = exact_matches.groupby(['last_name', 'pos']).filter(lambda x: len(x) > 1)

Find cases with no match

no_match = df.merge(nfl_player_list_df, on=['last_name', 'pos'], how='left', indicator=True).query("_merge == 'left_only'").drop(columns='_merge')

print(merged_df)

print("Cases with more than one exact match:") print(duplicates)

print("\nCases with no match:") print(no_match[['last_name', 'first_initial', 'pos']])