Home > Mobile >  How to create a dictionary from two dataframes mapping col1 of 1st df to col1 of 2nd df, and do this
How to create a dictionary from two dataframes mapping col1 of 1st df to col1 of 2nd df, and do this

Time:10-13

df1

1_A   2_A  3_A
3.3   nan   nan
3.3   nan   nan
nan   4.3   nan
nan   nan   3.2
nan   nan   3.5

df2

1_B   2_B  3_B
83   nan   nan
87   nan   nan
nan   64   nan
nan   nan   66
nan   nan   68

Desired list of dicts :

[{83 : 3.3 },{87 :3.3 },{64 :4.3 },{66 :3.2 },{68: 3.5}]
       

CodePudding user response:

In your case stack

d = dict(zip(df2.stack(),df1.stack()))
d
Out[58]: {83.0: 3.3, 87.0: 3.3, 64.0: 4.3, 66.0: 3.2, 68.0: 3.5}
  • Related