Skip to content

PierreMarion23/ipypivot

Repository files navigation

ipypivot

Binder

1 - Overview

This is a jupyter widget (or ipywidget) wrapping the very convenient pivotTable.js library.

It enables to display and embed a pivotTable in a Jupyter notebook in a few Python lines.

2 - Install

From pip:

$ pip install ipypivot

From conda:

$ conda install -c conda-forge ipypivot

For more info about jupyter widgets (installation process, packaging and publishing), and also tips about the development of custom widgets, see this tutorial repo. All what's written there is also true for this package, just changing the name first-widget into ipypivot.

3 - User Guide

See the demo notebook for examples and explanations.

In short:

  • The 2 pivotTable.js functions pivot() and pivotUI() are tranparently accessible.
  • The data is expected in pandas DataFrame format.
  • The options are input as an option helper object (Pivot_Options or PivotUI_Options)
  • Note: the range of possible options for pivot() and pivotUI() differ - but there is overlap.

Basic examples:

df = pd.DataFrame(data=[{'color': 'blue', 'shape': 'circle'},
                        {'color': "red", 'shape': 'triangle'}])

# pivot()
p = pt.Pivot(df_data=df)
opts = p.options
opts.rows = ['color']
opts.cols = ['shape']
display(p)

# pivotUI
p = pt.PivotUI(df_data=df)
opts = p.options
opts.rows = ['color']
opts.cols = ['shape']
display(p)

4 - Alternative

The repo branch alt contains an alternative widget PivotUI widget.
It has the same the same features but is implemented in pure web (buttons and 'Last Save' fields).
As opposed to the master branch which implements a combo of core and custom widgets.
The latter is more modular and flexible. In this case it is also slightly more complex.
But it may serve as an example for building a Jupyter widget from several component widgets.

5 - Credit

This repo is the result from a collaboration between oscar6echo, ocoudray, and PierreMarion23.

For more context, read the article Authoring Custom Jupyter Widgets - A Hands-On Guide on the Jupyter Blog.