#!/usr/bin/env python # coding: utf-8 # In[ ]: flex_orientation = "rows" flex_source_code = "https://github.com/danielfrg/jupyter-flex/blob/master/examples/widgets/qgrid.ipynb" # In[ ]: import numpy as np import pandas as pd import ipywidgets as widgets import qgrid # In[ ]: np.random.seed(42) # ### Regular DataFrame # In[ ]: randn = np.random.randn df_types = pd.DataFrame({ 'A' : pd.Series(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04', '2013-01-05', '2013-01-06', '2013-01-07', '2013-01-08', '2013-01-09'],index=list(range(9)),dtype='datetime64[ns]'), 'B' : pd.Series(randn(9),index=list(range(9)),dtype='float32'), 'C' : pd.Categorical(["washington", "adams", "washington", "madison", "lincoln","jefferson", "hamilton", "roosevelt", "kennedy"]), 'D' : ["foo", "bar", "buzz", "bippity","boppity", "foo", "foo", "bar", "zoo"] }) df_types['E'] = df_types['D'] == 'foo' # In[ ]: out = widgets.Output() out # ### qgrid # In[ ]: qgrid_widget = qgrid.show_grid(df_types, show_toolbar=True) qgrid_widget # In[ ]: qgrid_widget = qgrid.show_grid(df_types, show_toolbar=True) qgrid_widget # In[ ]: def handle_all_events(event, qgrid_widget): with out: out.clear_output() display(qgrid_widget.get_changed_df()) # In[ ]: from traitlets import All # In[ ]: qgrid_widget.on(All, handle_all_events) # In[ ]: # Trigger output handle_all_events(None, qgrid_widget) # In[ ]: