Generate HTML reports with Python, Pandas, and Plotly

The report generated by the IPython notebook described in this post (or this Python script) can be downloaded here.

Generating reports or dashboards at your company? Consider Plotly Enterprise – fully secure, on-premise instances of Plotly.

Plotly generates rich, interactive graphs using d3.js. You can easily create and embed these graphs into HTML reports to share with your team using a well-known data science language, like Python, MATLAB, or R. This post shows you how using Python and Pandas.

If you’re new to Pandas, we recommend these free, online tutorials:

Learn Pandas collection by Hernan Rojas.

Pandas Cookbook  collection by Julia Evans.

Open this IPython notebook to follow along with the steps below.

step 1: create the plotly graphs you want to embed

You can embed any Plotly graph into an HTML report as an iframe.  The syntax for embedding is described here.

We recommend generating the graphs and report containing them in the same Python script, as in this IPython notebook. This way, you can automatically generate new reports with the latest data, optionally using a task scheduler like cron.

You can get started with the Plotly Python client in under 5 minutes – see here for a walk-through.

STEP 2: Write a script that creates an html report

The last section of the IPython notebook (or this Python script) creates this HTML document as a string, then writes it to a file.

We recommend the css libraries Bootstrap and Skeleton for quick, clean styling of HTML reports.

Questions? Suggestions? Reach us through StackOverflow, Twitter, or feedback[at]plot[dot]ly.