I have a dataframe in Pandas that has columns that will correspond to the key and value of a dict.
for values in ['A','B']:
MYDICT[values] = [] # Initialize to empty list
Name ID othercolumns
A 5 ...
B 6 ...
A 3 ...
I am trying to find a simple way to assign every value of Name to ID so MYDICT[NAME].append(ID)
The solution I currently have is to iterate over every row in the dataframe
for index, x in df.iterrows():
WINNERS[x['Name']].append(x['ID'])
Is there a better way to do this without having to use iterrows()?