Qgrid is an IPython extension which uses a javascript library called SlickGrid to render pandas DataFrames within an IPython notebook. It's being developed for use in Quantopian's hosted research environment, and this notebook demonstrates the current state of the project.
Qgrid renders pandas DataFrames as SlickGrids, which enables users to explore the entire contents of a DataFrame using intuitive sorting and filtering controls. It's designed to be used within IPython notebook, and it's also fully functional when rendered in nbviewer.
In [1]:
import qgrid
In [2]:
qgrid.nbinstall(overwrite=True) # copies javascript dependencies to your /nbextensions folder
In [3]:
qgrid.set_defaults(remote_js=True, precision=4)
In [4]:
import pandas as pd
import numpy as np
randn = np.random.randn
pd.set_option('display.max_rows', 8)
from pandas.io.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,
)
In [5]:
spy
Out[5]:
In [6]:
qgrid.show_grid(spy)
By default, columns are stretched to fill the full width of the grid area. That doesn't work if you have hundreds of columns, so you can change this behavior by using the forceFitColumns
and defaultColumnWidth
SlickGrid options. See https://github.com/mleibman/SlickGrid/wiki/Grid-Options for the full list of SlickGrid options that you can configure:
In [7]:
qgrid.show_grid(spy, grid_options={'forceFitColumns': False, 'defaultColumnWidth': 200})
In [8]:
tuples = list(zip(*[['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]))
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
multi_index_df = pd.DataFrame(randn(8, 2), index=index, columns=['A', 'B'])
In [9]:
multi_index_df
Out[9]:
In [10]:
qgrid.show_grid(multi_index_df)
API documentation is hosted on readthedocs: http://qgrid.readthedocs.org/en/latest/
The API documentation can also be accessed via the "?" operator in IPython. To use the "?" operator, type the name of the function followed by "?" to see the documentation for that function, like this:
qgrid.nbinstall?
qgrid.show_grid?
qgrid.set_defaults?
qgrid.set_grid_options?
git clone git@github.com:quantopian/qgrid.git
This is an easy way to get qgrid to run directly from the source code. IPython notebook will look in it's working directory for modules to load, so qgrid will immediately become available for importing.
ipython notebook --notebook-dir=~/path/to/qgrid/repo
It's not always convenient to use the qgrid repository as your working directory for IPython noteboook, so I often create symbolic-links from qgrid's source code into the "/nbextensions" and "/extensions" folders under my IPython directory.
In [ ]:
import qgrid
In [ ]:
qgrid.nbinstall(overwrite=True) # use overwrite=True to keep your /nbextensions folder up to date during development