Skip to content

Instantly share code, notes, and snippets.

@mwouts
Last active February 21, 2025 15:06
Pandas DataFrames as interactive HTML DataTables

Pandas DataFrames as interactive HTML DataTables

In Jupyter Notebook, Jupyter Lab, Google Colab, VS Code and PyCharm

Pandas DataFrames are central to Data Analysis in Python. In this post, we introduce the itables Python package that enhances how these DataFrames are displayed, by turning them into interactive HTML DataTables.


Using itables is as simple as

from itables import init_notebook_mode
init_notebook_mode(all_interactive=True)

Then every DataFrame will appear as an interactive table:

import world_bank_data as wb

df = wb.get_countries()
df

Of course, you can use itables for selected tables only, in that case, you'll do

from itables import init_notebook_mode, show
init_notebook_mode(all_interactive=False)

show(df)

Our package is a thin wrapper on datatables.net (just like DT which inspired itables). Almost all the formatting options of datatables.net are available in itables - pass them to the show function or set them globally in itables.options, as documented in our README (try it on Binder).


Using itables has the following advantages:

  • You can explore, scroll, sort and even filter the table interactively
  • The interactive table takes less vertical space than the default Pandas representation
  • The full dataset is embedded in the table, not only 100 rows (for tables above 64KB a down-sampling is applied, but you can increase that threshold)
  • ⭐New in itables>=0.4.0⭐ It works in all the notebooks editors we have tested: Jupyter Notebook, Lab, Colab, VS Code, PyCharm
  • And the interactive tables also work when the notebook is exported as an HTML file (with jupyter nbconvert or Download as HTML)

The itables package was created by Marc Wouts in 2019. In the recent weeks, with the release of itables>=0.4.0, we finally solved the issue of making it work in Jupyter Lab and other editors. Marc would like to thank François Wouts for his precious help on transitioning to ES modules, and Allan Jardine, the author of datatables.net, for his support on the datatables.net forum.


A few other packages that let you explore your DataFrames interactively are

Unlike the above packages, itables does not require a live kernel (use voila if you need one). The table data is simply embedded in the notebook outputs, and for this reason, the HTML export of an itables notebook just works.


Please let us know how itables works for you. Your contributions are welcome! Star the project on GitHub, report your issues, or even join forces for building an offline mode or supporting the datatables extensions!

Appendix: screenshots of itables in various notebook editors

Jupyter Notebook

Jupyter Notebook

Jupyter Lab

Jupyter Lab

Jupyter NBconvert or 'Download as HTML'

HTML

Google Colab

Google Colab

Visual Studio Code

Visual Studio Code

PyCharm

PyCharm

Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kburchfiel
Copy link

This is fantastic! Thanks so much for this update--the HTML export process works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment