You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python requests响应无法解析data对象,如何生成DataFrame?

How to Extract the 'data' Field from TripAdvisor API JSON Response to Create a Pandas DataFrame?

I'm working with the TripAdvisor Reviews API, and right now I'm successfully making a GET request and receiving a text-formatted JSON response. Here's my code for the API call:

import requests
import json
from pandas import json_normalize

url = "https://tripadvisor1.p.rapidapi.com/reviews/list"
querystring = {"limit":"20","currency":"USD","lang":"en_US","location_id":"2269364"}
headers = { 'x-rapidapi-host': "xxx", 'x-rapidapi-key': "xxx" }
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)

My goal is to turn this response into a clean Pandas DataFrame. I looked up some tutorials and tried this method:

d = json.loads(response.text)
e = json_normalize(d)

But the output isn't what I want — the DataFrame ends up including top-level metadata instead of the actual review data I need. I noticed the reviews are all nested under the 'data' key in the JSON structure.

Could someone help me adjust my code to correctly extract the 'data' field and generate the proper DataFrame? Also, feel free to suggest how I can make this problem description clearer for future questions!

内容的提问来源于stack exchange,提问作者Davide Lorino

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 13:17:52