Reputation: 193
Folks,
I have a huge Python list which I created from a MongoDB query, it looks like this:
documents[0]['person']
Output:
{'phone': '3368988989898989898',
'name': 'PABLO',
'age': 27}
I wish to create a dataframe that looks like a traditional database:
PHONE | NAME | AGE
336...| PABLO| 27
335...| PEDRO| 32
How can I convert this list to a Pandas dataframe so I can write it to my relational database?
Upvotes: 1
Views: 128
Reputation: 323326
IIUC with pd.DataFrame
and apply(pd.Series)
documents=[{'person':{'phone': '3368988989898989898',
'name': 'PABLO',
'age': 27}},{'person':{'phone': '3368988989898989898',
'name': 'PEDRO',
'age': 35}}]
pd.DataFrame(documents).person.apply(pd.Series)
Out[920]:
age name phone
0 27 PABLO 3368988989898989898
1 35 PEDRO 3368988989898989898
Upvotes: 1