gpt4 book ai didi

python - 如何将 GET 请求中的 Json 转换为 pandas 数据帧

转载 作者:太空宇宙 更新时间:2023-11-03 20:27:23 24 4
gpt4 key购买 nike

我正在使用 GoToWebinar API 从网络研讨会获取数据。我做了所有事情,但我的脚本中唯一缺少的一点是将我获得的 Json 转换为 pandas 中的数据帧,以便我可以进行分析。

我得到的Json文件具有以下结构(我屏蔽了数据):

{
"_embedded": {
"webinars": [
{
"webinarKey": "GGGGGGGGGGGGGGGG",
"webinarId": "BBBBBBBBBBB",
"organizerKey": "RRRRRRRRRRRRR",
"omid": "RRRRRRRRRRR",
"accountKey": "WWWWWWWWWWW",
"recurrenceKey": "EEEEEEEEEEEEEEEEE21",
"subject": "LEEEEEEEEEESEon",
"description": "EEEEEEEEEEEEE",
"times": [
{
"startTime": "2019-07-01T13:00:00Z",
"endTime": "2019-07-01T13:30:00Z"
}
],
"timeZone": "America/New_York",
"locale": "en_US",
"status": "UPDATED",
"approvalType": "AUTOMATIC",
"registrationUrl": "https://attendee.gotowebinar.com/rt/XXXXXXXXXXXXXXXX",
"impromptu": false,
"isPasswordProtected": false,
"recurrenceType": "series",
"experienceType": "broadcast",
"registrationSettingsKey": "DDDDDDDD"
},
{
"webinarKey": "GGGGGGGGGGGGGGGG",
"webinarId": "BBBBBBBBBBB",
"organizerKey": "RRRRRRRRRRRRR",
"omid": "RRRRRRRRRRR",
"accountKey": "WWWWWWWWWWW",
"recurrenceKey": "EEEEEEEEEEEEEEEEE21",
"subject": "LEEEEEEEEEESEon",
"description": "EEEEEEEEEEEEE",
"times": [
{
"startTime": "2019-07-01T13:00:00Z",
"endTime": "2019-07-01T13:30:00Z"
}
],
"timeZone": "America/New_York",
"locale": "en_US",
"status": "UPDATED",
"approvalType": "AUTOMATIC",
"registrationUrl": "https://attendee.gotowebinar.com/rt/XXXXXXXXXXXXXXXX",
"impromptu": false,
"isPasswordProtected": false,
"recurrenceType": "series",
"experienceType": "broadcast",
"registrationSettingsKey": "DDDDDDDD"
},
..other webinars.....
]
},
"page": {
"size": 10,
"totalElements": 26,
"totalPages": 3,
"number": 0
}
}

这是我的代码,我基本上不知道如何进行。我尝试了 DataFrame.from_dict、read_json 以及此处提供的解决方案:Convert JSON data from Request into Pandas DataFrame

'''Getting the webinar lists'''
base_url = 'https://api.getgo.com/G2W/rest/v2'

##setting up paramters
param_1 = '2019-07-01T10%3A00%3A00Z'
param_2 = '2019-09-01T10%3A00%3A00Z'

##buidling the path
path = base_url + '/accounts/' + account_key + '/webinars?fromTime=' + param_1 +'&toTime=' + param_2
print(path)

headers = {'accept' : 'application/json' , 'Authorization' : access_token}

webinars_req = session.get(path, headers = headers)

webinars_json = webinars_req.json()

我想要一个包含所有内部标签(例如 webinarkey、webinarid 等)作为具有相应值的列的数据框...

希望大家帮忙!

最佳答案

您可以尝试requests模块

import requests

webinars_req = requests.get(path, headers = headers)
df = pd.read_json(webinars_req.text, ignore_index=True)

关于python - 如何将 GET 请求中的 Json 转换为 pandas 数据帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57726672/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com