Python requests响应无法解析data对象,如何生成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

