Python  - Panda - DataReader                                    Home : www.sharetechnote.com

 

 

 

 

Panda - Data Reader

 

Pada Data Reader Package is the library to pull out the data directly from various web source (e.g, Yahoo Finance, Google Finance etc). However, both Data Reader package and the interface supported by the data source keep changing, the examples shown here may or may not work on your system. For example, Example 1 worked with no problem when I ran it with Python 3.5 on Windows 7 around Jan 2017, but it didn't work when I tried it with Python 3.62 on Windows 10 in Jan 2018 (See NOTE section in Example on how I fixed the problem).  

 

 

Example 1 >

 

DataReader01.py

import pandas as pd

import pandas.io.data as pdr

import matplotlib.pyplot as plt

import datetime as dt

 

date_start = dt.datetime(2016,1,1)

date_end = dt.datetime(2016,12,31)

symbol = 'GOOGL'

daily_data = pdr.DataReader(symbol,"google",date_start,date_end)

 

plt.plot(daily_data.ix[:,['High','Low']])

plt.show()

 

 

Result :---------------------------------------------------------

 

 

NOTE : Even thought the commands worked in Python 3.5, I got following warnings.

 

Warning (from warnings module):

  File "C:\Python35\lib\site-packages\pandas\io\data.py", line 35

    FutureWarning)

FutureWarning:

The pandas.io.data module is moved to a separate package (pandas-datareader) and will be removed from pandas in a future version.

After installing the pandas-datareader package (https://github.com/pydata/pandas-datareader), you can change the import ``from pandas.io import data, wb`` to ``from pandas_datareader import data, wb``.

 

 

With the exactly same code on Python 3.62, I got following error and execution failed.

 

Traceback (most recent call last):

  File "C:/RyuCloud/Python/panda_DataReader01.py", line 2, in <module>

    import pandas.io.data as pdr

  File "C:\....\Python\Python36-32\lib\site-packages\pandas\io\data.py", line 2, in <module>

    "The pandas.io.data module is moved to a separate package "

ImportError: The pandas.io.data module is moved to a separate package (pandas-datareader). After installing the pandas-datareader package (https://github.com/pydata/pandas-datareader), you can change the import ``from pandas.io import data, wb`` to ``from pandas_datareader import data, wb``.

 

 

To Fix this problem,

First I tried as instructed here . However, the instruction command in the page didn't work on my system (Windows 10 and Python 3.62). So I manually downloaded the whl file pandas_datareader-0.5.0-py2.py3-none-any.whl from here and installed using pip as follows.

 

C:\Python36-32>pip install pandas_datareader-0.5.0-py2.py3-none-any.whl

 

 

 

Example 2 >

 

DataReader01.py

from pandas_datareader.data import Options

 

aapl = Options('aapl', 'yahoo')

data = aapl.get_all_data()

 

print(data.iloc[0:5, 0:5])

     

                                                  Last     Bid     Ask  Chg  \

    Strike Expiry     Type Symbol                                             

    2.5    2018-01-19 call AAPL180119C00002500  168.04  166.15  167.40  0.0   

                      put  AAPL180119P00002500    0.02    0.00    0.02  0.0   

           2018-02-16 call AAPL180216C00002500  170.91  172.20  172.85  0.0   

           2018-04-20 call AAPL180420C00002500  170.95  166.50  167.50 -1.0   

                      put  AAPL180420P00002500    0.01    0.00    0.01  0.0   

     

                                                  PctChg  

    Strike Expiry     Type Symbol                         

    2.5    2018-01-19 call AAPL180119C00002500  0.000000  

                      put  AAPL180119P00002500  0.000000  

           2018-02-16 call AAPL180216C00002500  0.000000  

           2018-04-20 call AAPL180420C00002500 -0.581564  

                      put  AAPL180420P00002500  0.000000