proper date input for pandas datareader?

1.5k views Asked by At

Both date formats below (string or datetime) used to work. However, in the last few days these lines only output the last year's worth of data, regardless the year I specify (here 2012):

import pandas_datareader.data as wb
import datetime
start = datetime.datetime(2012,1,1)
end = datetime.datetime(2012,12,31)
df = wb.DataReader ('GE', 'google', '2012, 1, 1', '2012, 12, 31') # doesn't work
print (df)
df2 = wb.DataReader ('GE', 'google', start, end) # doesn't work
print (df2)

abbreviated output for both:

            Open   High    Low  Close    Volume
Date                                            
2016-09-15  29.55  29.85  29.42  29.75  35262527
...
2017-09-13  23.93  24.18  23.92  24.11  38629676
2

There are 2 answers

1
bud fox On

during the process of fixing this, i upgraded to the most current version of pandas (0.20.3) and pandas-datareader (0.5.0). that did not fix the code in the question. the problem appears to be trying to use google as the source. the code below runs correctly but uses yahoo as the source. however, it fails when trying to use google as the source.

from pandas_datareader import data, wb
from datetime import date
start = date (2012, 1, 1)
end = date (2012, 12, 31)
df = data.DataReader ('GE', 'yahoo', start, end)
print (df)
1
user23497082 On
    import yfinance as yfin
    import datetime

    start = datetime.datetime(2012,1,1)
    end   = datetime.datetime(2012,12,31)

    tickerGE2 = yfin.Ticker('GE')
    dfGE2 = tickerGE2.history(  period="max", start=start, end=end)
    print (dfGE2)

Sample output

                             Open        High         Low       Close  \

Date
2012-01-03 00:00:00-05:00 85.363812 86.628115 85.363812 85.972549
2012-01-04 00:00:00-05:00 85.738404 87.096361 85.597928 86.909058
2012-01-05 00:00:00-05:00 86.440802 87.096367 85.644761 86.862236