2

I just switched from pandas.io to pandas_datareader and I'm having difficulties pulling in just Adjusted Close prices. before I could use the following code

pd.io.data.get_data_yahoo(stock, start, end)['Adj Close']

now when I try the datareader (imported as web) it does not work.

web.get_data_yahoo(stock, start, end)['Adj Close'] 

I've tried to find documentation to see if there is a new argument that the pandas_datareader uses, but I have had no luck. Is there anyway to pull in just Adjusted Close data using the new pandas library?

Evy555
  • 215
  • 2
  • 9
  • 19

4 Answers4

6

i would use DataReader for that:

In [61]: from pandas_datareader.data import DataReader

In [62]: DataReader('AAPL', 'yahoo', '2016-06-25', '2016-06-30')['Adj Close']
Out[62]:
Date
2016-06-27    92.040001
2016-06-28    93.589996
2016-06-29    94.400002
Name: Adj Close, dtype: float64

actually your code works as well (pandas 0.18.1 and pandas_datareader 0.2.1):

In [63]: import pandas_datareader.data as web

In [64]: web.get_data_yahoo('AAPL', '2016-06-25', '2016-06-30')
Out[64]:
                 Open       High        Low      Close    Volume  Adj Close
Date
2016-06-27  93.000000  93.050003  91.500000  92.040001  45489600  92.040001
2016-06-28  92.900002  93.660004  92.139999  93.589996  39311500  93.589996
2016-06-29  93.970001  94.550003  93.629997  94.400002  36427800  94.400002

In [65]: web.get_data_yahoo('AAPL', '2016-06-25', '2016-06-30')['Adj Close']
Out[65]:
Date
2016-06-27    92.040001
2016-06-28    93.589996
2016-06-29    94.400002
Name: Adj Close, dtype: float64
MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
0

This solution is no longer viable. When I run:

import pandas_datareader.data as web
web.get_data_yahoo('AAPL')

This yields:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='ichart.finance.yahoo.com', port=80): Max retries exceeded with url: /table.csv?a=0&ignore=.csv&s=AAPL&b=1&e=7&d=6&g=d&f=2017&c=2010 (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))

Looks like Quanld could provide a better solution

Anthony
  • 61
  • 1
  • 7
  • Yeah Yahoo has had some issues recently. I switched to google. – Evy555 Jul 07 '17 at 18:42
  • @Evy555 have you found a solution for getting adjusted close data? (concerned about dividends) I don't believe google's close field is adjusted. – Anthony Jul 07 '17 at 19:29
  • Unfortunately, Google still doesn't adjust prices for dividends. I haven't found another source that does. – Evy555 Oct 05 '17 at 22:01
0

Reading from Yahoo is broken. Use Google instead, if you can. For example:

df = web.DataReader("AAPL", 'google', start, end)
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
0

Try this:

from pandas_datareader import get_data_yahoo as gy

X = gy('AAPL','2019-01-01','2019-03-15')['Adj Close']

print(X.head())