I'm trying to iterate over a column in a dataframe and when the value matches a key from my dictionary it should then replace the value in another column with the value of the matching key.
df = pd.DataFrame({'id': ['123', '456', '789'], 'Full': ['Yes', 'No', 'Yes'], 'Cat':['','','']})
cats = {'123':'A', '456':'B', '789':'C'}
for val in df.id:
for key, cat in cats.items():
if key == val:
df.Cat.loc[(df.Full == 'Yes')] = cat
df
id Full Cat
0 123 Yes C
1 456 No
2 789 Yes C
I would expect id 123 to have a Cat of 'A' but instead it only returns 'C'
Can anyone explain to me why the it isn't iterating over the keys in dictionary?