Search code examples
pythonpandasdatareaderyahoo-finance

Get "Adj Close" using pandas DataReader


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?


Solution

  • 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