Danielle Song
Danielle Song

Reputation: 1

Convert NOAA JSON value to data frame in python

From NOAA API, I can get Boston hourly weather forecast information via JSON file. Here is the link: https://api.weather.gov/gridpoints/BOX/70,76 (This JSON file is too long to present comprehensively here, please kindly click the link to see it)

I want to convert some of the weather variables into data frame to proceed further calculation. The expected format is as below for temperature. I will use the same format to get precipitation, snowfall, humidity, etc. expected dataframe format

Now I cannot figure out how to convert it to the dataframe I want. Please kindly help....

For now, here is the best I can do, but still cannot extract validTime and values from Temperature

    import requests
    import pandas as pd
    response = requests.get("https://api.weather.gov/gridpoints/BOX/70,76")
    # create new variable forecast
    forecast=response.json()
    df1 = pd.DataFrame.from_records(forecast['properties']).reset_index() 
    df2=df1.loc[ :1 , ['temperature','quantitativePrecipitation', 'snowfallAmount', 'relativeHumidity',  'windGust', 'windSpeed', 'visibility']]
    df2

current output

Upvotes: 0

Views: 220

Answers (0)

Related Questions