I am trying to check a row value for a match in a dictionary and append the key to a new column.
Example:
group_ID = {
'Group A':[4738, 4812],
'Group B':[5888, 6551],
'Group C':[4487, 7888]
}
user_data = [['Alex',4812],['Bob',4487],['Clarke',5888]]
sample_df = pd.DataFrame(user_data,columns=['Name','User ID'])
print(sample_df)
Name User ID
0 Alex 4812
1 Bob 4487
2 Clarke 5888
Using this example, if 'User ID' in sample_df has a matching value in dictionary 'group_ID' then I would like to add a third column reflecting the key name like below:
Name User ID Group ID
0 Alex 4812 Group A
1 Bob 4487 Group C
2 Clarke 5888 Group B
Thanks in advance for the help!