In my dataframe, there is a column of dictionaries:
| ID | name | value | stats |
|---|---|---|---|
| {'mean': 154.0, 'median': 154.0, 'std': 0.0} | |||
| {'mean': 131.19, 'median': 93.68, 'std': 53.04} |
I need to break down that column as new columns
| ID | name | value | mean | median | std |
|---|---|---|---|---|---|
| 154.0 | 154.0 | 0.0 | |||
| 131.19 | 93.68 | 53.04 |
I tried to use pd.json_normalize as follow:
df2 = pd.json_normalize(df['stats'])
df2
But this way I lose the indexes in df2 and can't join them to add new columns to df. How should I do it?