I made a python request (curl), obtaining this JSON array, I want to convert it to Pandas Dataframe or even to a python dictioray to later convert it to Pandas Dataframe, but nothing works...
When I try to convert it like this:
import json
aDict = json.loads(response.text)
dataframe = pd.DataFrame.from_dict(aDict, orient="index")
compiler says: " AttributeError : 'list' object has no attribute 'values '"
print of response.text:
'[{"total":null,"items":[{"key":"time","label":"Time","value":"2021-07-14"},{"key":"agent","label":"Agent","value":"name_of_agent"},...
import json
import pandas as pd
aDict = json.loads('[{"total":null,"items":\
[{"key":"time","label":"Time","value":"2021-07-14"},\
{"key":"agent","label":"Agent","value":"name_of_agent"}]}]')
df = pd.DataFrame.from_dict(aDict[0]['items'])
df
key label value
0 time Time 2021-07-14
1 agent Agent name_of_agent
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.