I have a dataframe with dictionaries saved under two columns:
Name Trust_Value Affordability_Value
0 J. {'J.': 0.25, 'M.': 0.23} {'Z.': 0.024, 'M.': 0.34}
1 M. {'M.': 0.12, 'S.': 0.14} {'S.': 0.017, 'B.': 0.21}
1 C. {'S.': 0.21, 'N.': 0.13} {'D.': 0.015, 'B.': 0.22}
For each name I would like to have separates dataframes including Name of interest, Trust_Value (key and value in separate columns) and Affordability_Value (key and value in separate columns):
df1 (J.):
Name Trust_Key Trust_Value Affordability_Key Affordability_Value
0 J. J. 0.25 Z. 0.024
M. 0.23 M. 0.34
df2 (M.):
Name Trust_Key Trust_Value Affordability_Key Affordability_Value
0 M. M. 0.12 S. 0.017
S. 0.14 B. 0.021
df3 (C.):
Name Trust_Key Trust_Value Affordability_Key Affordability_Value
0 M. S. 0.21 D. 0.015
N. 0.13 B. 0.22
I have no difficulties to split key-value pairs: my difficulties are in generating different dataframes that can include these values in separate columns.
The output from df.head().to_dict() is the following (I took only the first three elements):
{'Name': {0: 'J.',
1: 'M.',
2: 'C.',
},
'Trust_Value': {0: {'J.': 0.25,
'M.': 0.23, 'D.': 0.22, 'S.':0.12,'N.':0.12}, 1: {'M.': 0.12, 'S.': 0.14, 'C.': 0.12, 'D.': 0.12}, 2: {'S.': 0.21, 'N.': 0.13, 'C.':0.34, 'D.':0.12, 'T.':0.42}}, 'Affordability_Value':{0: {'Z.': 0.024,
'M.': 0.34, 'D.': 0.21, 'X.':0.23,'N.':0.15}, 1: {'S.': 0.51, 'B.': 0.21, 'C.': 0.29, 'D.': 0.12}, 2: {'D.': 0.26, 'B.': 0.26, 'C.':0.38, 'D2.':0.25, 'T.':0.42}}}