Pandas - column with list of index for another data frame python

Viewed 339

I have a pandas data frame with one of its column holding index of another data frame, I want to create one more column in this data frame with dictionary holding index as key and value from a column in another data frame.

Example,

Dataset1

  A B C
0 9 1 [1,3]
1 7 2 [0,1]

In the above dataset, column C has indices of dataset2.

Dataset2
  A B C D
0 1 4 3 8
1 2 3 5 7
3 4 6 9 8

And my output dataset should have a new column in dataset1 with key as indices of dataset2 and value as values of column D from dataset2. So the output should look like,

Dataset1
   A   B    C    D
0  9   1  [1,3] {'1':'7','3':'8'}
1  7   2  [0,1] {'0':'8','1':'7'}

How do I achieve this? Thanks in advance.

1 Answers
Related