Search code examples
pythonpandasjupyter-notebookjupyter-contrib-nbextensions

display pandas dataframe into another tab


I am trying to display my pandas dataframe in another "Output View" tab as shown in this iamge...

https://github.com/quantopian/qgrid/blob/master/docs/images/events_api.gif

I am able to install and try the basic features of qgrid using following commands. But not able to get the exact view as shown above.

!pip install qgrid
!jupyter nbextension enable --py --sys-prefix qgrid
!jupyter nbextension enable --py --sys-prefix  widgetsnbextension

import qgrid
import pandas as pd
df = pd.read_csv('some.csv')

qgrid_widget = qgrid.show_grid(df, show_toolbar=True)
qgrid_widget

qgrid_widget.get_changed_df()

Solution

  • These commands should work:

    Pre-installation:

    1. Assume you have conda environment called "myenv"
    2. Assume you have jupyter-lab installed in that environment
    

    Installation of New Conda environment

    source activate myenv
    pip install qgrid
    jupyter labextension install qgrid
    jupyter labextension install @jupyter-widgets/jupyterlab-manager
    jupyter nbextension enable --py --sys-prefix qgrid
    jupyter nbextension enable --py --sys-prefix widgetsnbextension
    

    Load conda environment

    source activate myenv
    jupyter-lab
    create a notebook under environment myenv
    

    ------------------- These are just pre installation procedures -------
    ------------------- Here is how you use qgrid in jupyter lab ----------

    # Lets say you have a pandas dataframe `df`
    qgrid_widget = qgrid.show_grid(df.head(), show_toolbar=True)
    qgrid_widget
    qgrid_widget.get_changed_df()
    
    # right click on this cell
    # click Create New View for Output # it will create new tab
    # You will see the new window of dataframe
    

    Confirmation

    I just followed up the procedure for a new environment, and it works. enter image description here