0

I want to extract wind object's data from the following JSON string:

enter image description here

import pandas as pd
from urllib2 import Request, urlopen
import json
from pandas.io.json import json_normalize

request=Request('...')
response_weather = urlopen(request)
w = response_weather.read()
metar = json.loads(w)
wind = pd.DataFrame(json_normalize(metar['wind']))
print wind


KeyError: 'wind'

2 Answers 2

1

I want to extract wind object's data

Then you want you want metar['conditions']['wind']

And based on your screenshot, that key contains the following object: {direction: 60, directionIsVariable: false, speedKnots: "3.00"}

P.S. Since that's a single object, I'm not sure what you want to achieve by making it into a pandas.DataFrame

Sign up to request clarification or add additional context in comments.

1 Comment

I am appending pandas DataFrame with more readings of wind obtained from other requests
1

To get to the wind object, you first have to get the conditions object out of metar. Once you have the conditions object, you can then pull out the wind object.

Metar doesn't have a wind child, so metar['wind'] doesn't access anything. metar['conditions'] will work, because there is a conditions child.

Hope that helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.