Search code examples
pythonpandas-datareader

Python using pandas_datareader to read from FRED gives error no timezone found


I am trying to use pandas_datareader to read from FRED. Code is below but I get this error

  • GDP: No timezone found, symbol may be delisted

The code is taken from the doco https://pandas-datareader.readthedocs.io/en/latest/remote_data.html#remote-data-fred

import pandas_datareader.data as web
import datetime

start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2022, 1, 27)
gdp = web.DataReader('GDP', 'fred', start, end,ignore_tz=True)

I tried googling the error, I tried hard coding dates with time zones I also tired using ignore_tz argument set to True


Solution

  • NB: In Colab, I get an error with the keyword ignore_tz
    From Remote Data Access pandas_datareader documentation, it is not required.

    You can simply format your datetime to your preferred timezone using the datetime's timezone library.

    %%time
    
    ## import libraries
    import pandas_datareader.data as web
    import datetime
    
    ## timerange  ##Edit per @Jim comment
    start = datetime.datetime(2010, 1, 1)
    end = datetime.datetime(2022, 1, 27)
    
    ## Read St. Louis FED data
    ## Documentation at: https://pandas-datareader.readthedocs.io/en/latest/remote_data.html#fred
    ## Read 'GDP' data from FRED within the timerange
    gdp = web.DataReader('GDP', 'fred', start, end)
    
    ## display retrieved dataframe from source
    gdp
    

    I got output as below (showing the first 5).

    CPU times: user 24 ms, sys: 903 µs, total: 24.9 ms
    Wall time: 283 ms
    Date         GDP    
    2010-01-01  14764.611
    2010-04-01  14980.193
    2010-07-01  15141.605
    2010-10-01  15309.471
    2011-01-01  15351.444
    

    PS: I'll give this another shot on my system to handle the ignore_tz with better option. However, ignore_tz = True would not be the option.