Historical inventory data
When I try to get stock prices from yahoo or google (I've tried both), it keeps returning with this error. I don't know what this means or how to fix it. I have used this code before and it worked well. Could you please help me with this error and a solution to fix it. Thank.
import datetime as dt
import pandas as pd
import pandas_datareader.data as web
start = dt.datetime(2000,1,1)
end = dt.datetime(2004,1,1)
df= web.DataReader('TSLA', 'yahoo', start, end)
print(df.head)
ConnectionError: HTTPConnectionPool (host = 'ichart.finance.yahoo.com', port = 80): Maximum retries exceeded with url: /table.csv? A = 0 & ignore = .csv & s = TSLA & b = 1 & e = 1 & d = 0 & g = d & f = 2004 & c = 2000 (caused by NewConnectionError (': Unable to establish new connection: [Errno 8] nodename or servname provided or unknown',))
+3
source to share
2 answers
Here's a workaround I found:
# Define the instruments to download. We would like to see Apple, Microsoft and the S&P500 index.
tickers = ['AAPL', 'MSFT', 'SPY']
# Define which online source one should use
data_source = 'google'
# We would like all available data from 01/01/2000 until 12/31/2016.
start_date = '2010-01-01'
end_date = '2016-12-31'
# User pandas_reader.data.DataReader to load the desired data. As simple as that.
panel_data = data.DataReader(tickers, data_source, start_date, end_date)
# Getting just the adjusted closing prices. This will return a Pandas DataFrame
# The index in this DataFrame is the major index of the panel_data.
close = panel_data.ix['Close']
# Getting all weekdays between 01/01/2000 and 12/31/2016
all_weekdays = pd.date_range(start=start_date, end=end_date, freq='B')
# How do we align the existing prices in adj_close with our new set of dates?
# All we need to do is reindex close using all_weekdays as the new index
close = close.reindex(all_weekdays)
close.head(10)
from http://www.learndatasci.com/python-finance-part-yahoo-finance-api-pandas-matplotlib/
0
source to share