NOTE: Not every geographical location works well with pandas datareader, your firewall may also block it!
Functions from pandas_datareader.data
and pandas_datareader.wb
extract data from various Internet sources into a pandas DataFrame. Currently the following sources are supported:
World Bank
OECD
Oanda currency historical rate
It should be noted, that various sources support different kinds of data, so not all sources implement the same methods and the data elements returned might also differ. Visit the <a href="https://pandas-datareader.readthedocs.io/en/latest/remote_data.html" target = "_blank">pandas-datareader site</a> for more details.
If you encounter a module not found error
when you try to use the pandas_datareader
module. This is because Pandas Datareader Module is not part of Anaconda Dist.
To inatall Pandas Datareader
At Anaconda prompt:
conda install -c https://conda.anaconda.org/anaconda pandas-datareader
Alternatively, at command prompt
pip install pandas-datareader
import pandas_datareader.data as web
import datetime
start = datetime.datetime(2015, 1, 1)
end = datetime.datetime(2017, 1, 1)
facebook = web.DataReader("FB", 'google', start, end)
facebook.head()
The Options class allows the download of options data from Google Finance.
from pandas_datareader.data import Options
fb_options = Options('FB', 'google')
The get_options_data method downloads options data for specified expiry date and provides a formatted DataFrame with a hierarchical index, so its easy to get to the specific option you want.
Available expiry dates can be accessed from the expiry_dates property.
data = fb_options.get_options_data(expiry=fb_options.expiry_dates[0])
data.head()
import pandas_datareader.data as web
import datetime
start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2017, 1, 1)
gdp = web.DataReader("GDP", "fred", start, end)
gdp.head()
import pandas_datareader.data as web
import datetime
start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2010, 5, 1)
inflation = web.DataReader(['CPIAUCSL', 'CPILFESL'], 'fred', start, end)
inflation.head()