I have a dataframe and 2 separate dictionaries. Both dictionaries have the same keys but have different values. dict_1 has key-value pairs where the values are unique ids that correspond with the dataframe df. I want to be able to use the 2 dictionaries and the unique ids from the dict_1 to append the values of dict_2 into the dataframe df.
Example of dataframe df:
col_1 col_2 id col_3
100 500 a1 478
785 400 a1 490
... ... a1 ...
... ... a2 ...
... ... a2 ...
... ... a2 ...
... ... a3 ...
... ... a3 ...
... ... a3 ...
... ... a4 ...
... ... a4 ...
... ... a4 ...
Example of dict_1:
1:['a1', 'a3'],
2:['a2', 'a4'],
3:[...],
4:[...],
5:[...],
.
Example of dict_2:
1:[0, 1],
2:[1, 1],
3:[...],
4:[...],
5:[...],
.
I'm trying to append the data from dict_2 using id's from dict_1 into the main df.
In a sense add the 2 values (or n values) from the lists of dict_2 as 2 columns (or n columns) into the df.
Resultant df:
col_1 col_2 id col_3 new_col_1 new_col_2
100 500 a1 478 0 1
785 400 a1 490 0 1
... ... a1 ... 0 1
... ... a2 ... 1 1
... ... a2 ... 1 1
... ... a2 ... 1 1
... ... a3 ... 0 1
... ... a3 ... 0 1
... ... a3 ... 0 1
... ... a4 ... 1 1
... ... a4 ... 1 1
... ... a4 ... 1 1