Using Yahoo S&P 500 data with QGrid and JupyterΒΆ

QGrid is a dataframe viewer for Jupyter Notebook.

In this tutorial, we’ll use QGrid to display S&P 500 stock market data.

  1. Start Navigator.

  2. To install the QGrid and Pandas Datareader packages, follow the instructions in Finding and installing a package.

  3. To open a Jupyter Notebook, follow the instructions in Using an environment.

  4. Copy and paste the following code into the first cell:

    import qgrid
    import pandas as pd
    import pandas_datareader
    pd.set_option('display.max_rows', 8) # Prevents the grid from being too large
    from pandas_datareader.data import get_data_yahoo
    spy = get_data_yahoo(symbols='SPY', start=pd.Timestamp('2011-01-01'),
                   end=pd.Timestamp('2014-01-01'), adjust_price=True)
    spy
    
  5. To run the code, in the menu bar, click Cell then select Run Cells, or use the keyboard shortcut Ctrl-Enter.

    A Pandas DataFrame is created that contains the daily prices for the S&P 500 from 1/1/2011–1/1/2014 and displays the first four and last four rows of the DataFrame.

    ../../../_images/navigator-tutorial06.png

NOTE: The example code is taken from https://github.com/quantopian/qgrid and http://nbviewer.jupyter.org/gist/TimShawver/b4bc80d1128407c56c9a .