python
2017-01-26 1 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

그것은 DataFrame로 전환되지만 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

감사합니다. – Bhushan

관련 문제