I have to requests.get() two urls from yahoo utilizing YQL that returns a json object. I'm getting back a json objects that I store into a list(). Then I'm looping to parse the data and creating a dic to then create a pandas data frame. Happened that only one list is getting appended to the data frame. Seems like in the last iteration, the 2nd list overwrites the first list. At this point, I can't figure out how to iterate on the list to append() both elements of the list. Here is my code...
import requests
import pandas as pd
urls = ['https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20in%20(%22DIA%22%2C%22SPY%22%2C%22IWN%22)%20and%20startDate%20%3D%20%222015-01-01%22%20and%20endDate%20%3D%20%222015-10-31%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=',
'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20in%20(%22DIA%22%2C%22SPY%22%2C%22IWN%22)%20and%20startDate%20%3D%20%222015-11-01%22%20and%20endDate%20%3D%20%222016-08-31%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=']
for url in urls:
data = requests.get(url)
data_json = data.json()
quote_list = []
for quote in data_json['query']['results']['quote']:
quote_dic = {'symbol': quote['Symbol'],
'date': quote['Date'],
'volume': quote['Volume'],
'low': quote['Low'],
'high': quote['High'],
'open': quote['Open'],
'close': quote['Close'],
'adj_close': quote['Adj_Close']}
quote_list.append(quote_dic)
quote_df = pd.DataFrame(quote_list)
quote_df.to_csv('stocks.csv')
I need to be able to append the entire list() into the data frame. What would be the fix for this code?
jsonstraight to the data frame?