I have the following dataframes:
df1 = {'col1': {0: 'IL', 1: 'NE', 2: 'NE', 3: 'IL', 4: 'TX', 5: 'TX'},
'col2': {0: 'bob', 1: 'fred', 2: 'alex', 3: 'ted', 4: 'frank', 5: 'tim'}}
df2 = {'IL': {0},'NE': {0},'TX': {0}}
dataframes and expected result
I want to add the col 2 information from df1 to the correct column in df2. So far I have the following code:
for i in range(len(df1)):
if df1.loc[i,'col1'] == #header of df2
#add df1.loc[i,'col2'] to the header 'col1' matches with
I need help on how I can reference the header of df2 and then add the col 2 code to that specific header it matches with.