This is an extension of this question on pandas conversion from list of dicts
If the dataframe includes a dict within the dict
[{'points': 50, 'time': '5:00', 'year': 2010},
{'points': 25, 'time': '6:00', 'month': "february"},
{'points':90, 'time': '9:00', 'month': 'january'},
{'points_h1':20, 'details': {'width':10,'height:20}}]
So I would like to get this:
month points points_h1 time year details.width details.height
0 NaN 50 NaN 5:00 2010 NaN NaN
1 february 25 NaN 6:00 NaN NaN NaN
2 january 90 NaN 9:00 NaN NaN NaN
3 NaN NaN 20 NaN NaN 10 20
You may have guessed that I was using json_normalize
before and now have a dict
but converting to json
seems unintuitive to me here. I have tried list-comprehension
with pd.concat()
before finding the answer above which almost fixed my issues (converting my column to a list
and using pd.DataFrame(data)
)