Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 730
shantanuo Avatar asked Oct 27 '25 11:10

shantanuo


2 Answers

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

like image 64
BhishanPoudel Avatar answered Oct 30 '25 01:10

BhishanPoudel


Since this question has a bounty on it, I can't mark it as duplicate. To show the dataframe in another tab, you can use a little JavaScript. According to this post, here is a code that will show the dataframe in another tag:

from IPython.display import HTML
def View(df):
    css = """<style>
    table { border-collapse: collapse; border: 3px solid #eee; }
    table tr th:first-child { background-color: #eeeeee; color: #333; font-weight: bold }
    table thead th { background-color: #eee; color: #000; }
    tr, th, td { border: 1px solid #ccc; border-width: 1px 0 0 1px; border-collapse: collapse;
    padding: 3px; font-family: monospace; font-size: 10px }</style>
    """
    s  = '<script type="text/Javascript">'
    s += 'var win = window.open("", "Title", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=780, height=200, top="+(screen.height-400)+", left="+(screen.width-840));'
    s += 'win.document.body.innerHTML = \'' + (df.to_html() + css).replace("\n",'\\') + '\';'
    s += '</script>'
    return(HTML(s+css))

Then finally you can use the function to view a dataframe like this:

View(my_dataframe)

This should open the the dataframe in another tab.

like image 20
xilpex Avatar answered Oct 30 '25 00:10

xilpex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!