I have a dataframe with a column (e.g. features) that is in dictionary format, as shown below. I'd like to convert each key in the dict to a column. All the rows have the same dict keys, but different values. I found some solutions on SO that could convert a dict to columns, but under the condition that the keys of the dict is known, in my case, it is unknown. Any suggestion on how to achieve that?
|id1 |id2 |features |
+-------+-----------+------------------------------------------------------------------------+
|1341205|a232523 |{"attr1.feature1": 0.25, "attr1.feature2": 0.0, "attr2.feature1": -0.43}|
|553654 |a325933 |{"attr1.feature1": 0.3, "attr1.feature2": 0.70, "attr2.feature1": 0.11} |
|573786 |a9923823 |{"attr1.feature1": -0.1, "attr1.feature2": 0.20, "attr2.feature1": 0.12}|
Expected dataframe:
+-------+-----------+---------------+---------------+----------------+
|id1 |id2 |attr1.feature1 |attr1.feature2 |attr2.feature1 |
+-------+-----------+---------------+---------------+----------------+
|1341205|a232523 |0.25 |0.0 |-0.43 |
|553654 |a325933 |0.3 |0.70 |0.11 |
|573786 |a9923823 |-0.1 |0.20 |0.12 |