python
2017-01-26 5 views 1 likes 
1
import pandas as pd 
import urllib 
import time 
import sys 
baseurl = "https://query.yahooapis.com/v1/public/yql?" 
yql_bs_query = 'select * from yahoo.finance.historicaldata where symbol = "YHOO" and startDate = "2009-09-11" and endDate = "2010-03-10"' 
yql_bs_url = baseurl + urllib.parse.urlencode({'q':yql_bs_query}) + "&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=" 
bs_json = pd.io.json.read_json(yql_bs_url) 
bs_json.values 
YHOO = bs_json.values.tolist() 

このリストをデータフレームで変換することはできません。Yahoo Financeをデータフレームに変換する

答えて

0

これは、データフレームに変換されますが、JSONの形式であるため、フレームのみ1列と5行を持っています

{u'query': {u'count': 124, 
     u'created': u'2017-01-26T05:44:52Z', 
     u'diagnostics': {u'build-version': u'2.0.84', 
... 

は、あなただけの見積もりを取得するには、別途インデックスをJSONをダウンロードする必要がありますデータを変換し、DataFrameに変換してください:

# same code as above here: 
import pandas as pd 
import urllib 
import time 
import sys 
baseurl = "https://query.yahooapis.com/v1/public/yql?" 
yql_bs_query = 'select * from yahoo.finance.historicaldata where symbol = "YHOO" and startDate = "2009-09-11" and endDate = "2010-03-10"' 
yql_bs_url = baseurl + urllib.parse.urlencode({'q':yql_bs_query}) + "&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=" 

# now that you have the URL: 
import requests 

# download json data and convert to dict 
data = requests.get(yql_bs_url).json() 

# get quote data 
quote = data["query"]["results"]["quote"] 

# convert to dataframe 
quote = pd.DataFrame.from_dict(quote) 
+0

ありがとうございますsundance – Bhushan

関連する問題