I'm trying to expand nested json to pandas dataframe, but the offered solutions haven't worked for me.
My case is:
I have json data in MongoDB.
When I connect with this database, it works well, but the problem is when I need to expand nested json to pandas dataframes, because there are columns where I have json object.
index id name location
0 0001 George [{'country':'Colombia', 'department': 'Antioquia', 'city': 'Medellin'}]
1 0002 Gilberth [{'country':'Colombia', 'department': 'Antioquia', 'city': 'Medellin'}]
2 0003 Christopher [{'country':'Colombia', 'department': 'Antioquia', 'city': 'Medellin'}]
I need to convert to dataframe something like this:
index id name country department city
0 0001 George Colombia Antioquia Medellin
1 0002 Gilberth Colombia Antioquia Medellin
2 0003 Christopher Colombia Antioquia Medellin
Here I show how to read json data:
json_documents = list(properties.find({}))
df = pd.DataFrame(json_documents)
df.head(2)
Thanks in advance.