繁体   English   中英

使用 REST API JSON 响应作为数据在 ZA7F5F35426B9637411FC92317B 中构建报告

[英]Using REST API JSON response as data to build reports in Python

I am having really hard time converting a json response from the QuickBase API into Pandas dataframe so I can work and chart the data with Pandas and Chartly.

import requests
import json
token = "b5u67z_pgnr_dkqwwkbbmmhnzwcjd4cexbi893ux"
realm_hostname = "builderprogram-ypetrov.quickbase.com"
headers = {
    'QB-Realm-Hostname': realm_hostname,
    'User-Agent': 'Python_Reporting',
    'Authorization': 'QB-USER-TOKEN ' + token
}
body = {
    "from": "bq4zh7zip",
    "select": [
    7,
    11,
    16
    ]
}
r = requests.post(
'https://api.quickbase.com/v1/records/query',
headers = headers,
json = body
)
json_export = (json.dumps(r.json(),indent=4))
import pandas as pd
#everything works fine until here, I can print json_export and the data is there but can't continue from here onwards
pd.read_json(json_export)

API 请求详细信息在测试环境中有效,因此如果需要,请随时使用。
任何帮助将不胜感激!
问候!

假设您想将data中的信息转换为 pandas dataframe,那么您可以使用pd.json_normalize而不是pd.read_json

...
# your code
...

import pandas as pd
df = pd.json_normalize(json.loads(json_export)['data'])
print(df.head())

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM