I am attempting to use an API request to gather weather data and ultimately save the data to a CSV file with pandas.to_csv. The API request is working, but I get this error when I am trying to convert the API response from a dictionary to pandas. Any tips for what I am doing wrong is greatly appreciated:
TypeError: unhashable type: 'dict'
The last line in the code is what is messed up and the shell is returning an error:
from urllib.request import urlopen
import json
import pandas as pd
api_key = ""
date = "20170601"
zip_code = "53711"
response = urlopen("http://api.wunderground.com/api/%s/history_%s/q/%s.json" % (api_key, date, zip_code))
json_data = response.read().decode('utf-8', 'replace')
data = json.loads(json_data)
for observation in data['history']['observations']:
print("Date/Time: " + observation['date']['pretty'])
print("Temperature: " + observation['tempi'])
print("Humidity: " + observation['hum'])
df = pd.DataFrame([data], columns=data.keys())
The screen shot is what the data looks like in the shell output: