[Python] JSON to dataframe

2022. 4. 4. 08:11파이썬

json_normalize

import pandas as pd
import json
from pandas import json_normalize

data = '''
{
"Results":
         [
         { "id": "1", "Name": "Jay" },
         { "id": "2", "Name": "Mark" },
         { "id": "3", "Name": "Jack" }
         ],
"status": ["ok"]
}
    '''

info = json.loads(data)

df = json_normalize(info['Results']) #Results contain the required data
print(df)

출력:

id Name
0 1 Jay
1 2 Mark
2 3 Jack

출처 : https://www.delftstack.com/ko/howto/python-pandas/json-to-pandas-dataframe/