PythonDataScienceHandbook
PythonDataScienceHandbook copied to clipboard
How to convert Json file into Python in tabular form.
Create A DataFrame from dictionary
import pandas as pd
data = [{'name': 'abc', 'age': 25}, {'name': 'xyz', 'age': 30}]
df = pd.DataFrame.from_dict(data, orient='columns')
df
Out[1]:
name age
0 abc 25
1 xyz 30
If the Dictionary is nested you first need to normalize it
from pandas import json_normalize
data = [
{
'name': {
'first': 'abc',
'last': 'xyt'
},
'age': 25
},
{
'name': {
'first': 'def',
'last': 'pqr'
},
'age': 30
}
]
df = pd.DataFrame.from_dict(json_normalize(data), orient='columns')
df
Out[2]:
age name.first name.last
0 25 abc xyt
1 30 def pqr
you had made data in listed form ?? and inside it you took dictionary??if you want to make table then do it with help o fdata structure , and use connector