2021年3月23日星期二

Python Normalize JSON to DataFrame

I have been trying to normalize this JSON data for quite some time now, but I am getting stuck at a very basic step. I think the answer might be quite simple. I will take any help provided.

import json  import urllib.request  import pandas as pd    url = "https://www.recreation.gov/api/camps/availability/campground/232447/month?start_date=2021-05-01T00%3A00%3A00.000Z"  with urllib.request.urlopen(url) as url:      data = json.loads(url.read().decode())      #data = json.dumps(data, indent=4)    df = pd.json_normalize(data = data['campsites'], record_path= 'availabilities', meta = 'campsites')  print(df)  

My Expected df result is as following:

Expected DataFrame Output

https://stackoverflow.com/questions/66774175/python-normalize-json-to-dataframe March 24, 2021 at 11:06AM

没有评论:

发表评论