私が必要とするのは、各企業の追加のセクター列を持つ基本的な株データを持つCVSファイルだけです。ウィキペディアのセクターやテロップを入手するのは問題ありません。Quandlリクエストをフォーマットできますか?
Google/Yahooのデータはもう使用したくないので、私はQuandlを使用しようとしました。私は最近、それに基づいていくつかのテクニカルインジケータを作ったので、それは素晴らしいと思いました。エラー。
私はそれが私の要求をフォーマットすることができればまだ疑問があるので、私は問題があると仮定しますが、それを動作させる方法を考え出すことはできません。
ご迷惑をおかけして申し訳ありませんが、ありがとうございます。
from bs4 import BeautifulSoup
import requests
import pandas as pd
import lxml
import quandl as qdl
def get_ticker_and_sector(url='https://en.wikipedia.org/wiki/List_of_S%26P_500_companies'):
r = requests.get(url)
data = r.text
soup = BeautifulSoup(data, 'lxml')
table = soup.find('table')
sp500 = {}
for tr in table.find_all('tr')[1:]:
tds = tr.find_all('td')
ticker = tds[0].text
sector = tds[3].text
sp500[ticker] = sector
return sp500
if __name__ == '__main__':
sp500 = get_ticker_and_sector()
for i, (ticker, sector) in enumerate(sp500.items()):
stock_df = qdl.get('WIKI/%s', start_date="2010-12-11", end_date="2011-12-31")%(ticker)
stock_df['Name'] = ticker
stock_df['Sector'] = sector
if i == 0:
all_df = stock_df
else:
all_df = all_df.append(stock_df)
all_df.to_csv('all_sp500_data_2.csv')
エラー。
Traceback (most recent call last):
File "/home/tomek/tomek-workspace/pythons/udemy/lib/python3.5/site-packages/quandl/connection.py", line 55, in parse
return response.json()
File "/home/tomek/tomek-workspace/pythons/udemy/lib/python3.5/site-packages/requests/models.py", line 886, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/tomek/PycharmProjects/untitled4/get_file.py", line 30, in <module>
stock_df = qdl.get('WIKI/%s', start_date="2010-12-11", end_date="2011-12-31")%('ticker')
File "/home/tomek/tomek-workspace/pythons/udemy/lib/python3.5/site-packages/quandl/get.py", line 48, in get
data = Dataset(dataset_args['code']).data(params=kwargs, handle_column_not_found=True)
File "/home/tomek/tomek-workspace/pythons/udemy/lib/python3.5/site-packages/quandl/model/dataset.py", line 47, in data
return Data.all(**updated_options)
File "/home/tomek/tomek-workspace/pythons/udemy/lib/python3.5/site-packages/quandl/operations/list.py", line 14, in all
r = Connection.request('get', path, **options)
File "/home/tomek/tomek-workspace/pythons/udemy/lib/python3.5/site-packages/quandl/connection.py", line 36, in request
return cls.execute_request(http_verb, abs_url, **options)
File "/home/tomek/tomek-workspace/pythons/udemy/lib/python3.5/site-packages/quandl/connection.py", line 44, in execute_request
cls.handle_api_error(response)
File "/home/tomek/tomek-workspace/pythons/udemy/lib/python3.5/site-packages/quandl/connection.py", line 61, in handle_api_error
error_body = cls.parse(resp)
File "/home/tomek/tomek-workspace/pythons/udemy/lib/python3.5/site-packages/quandl/connection.py", line 57, in parse
raise QuandlError(http_status=response.status_code, http_body=response.text)
quandl.errors.quandl_error.QuandlError: (Status 400) Something went wrong. Please try again. If you continue to have problems, please contact us at [email protected]