1

Has anyone any experience of publishing a pandas pivot table to a html page? Its simple to publish a list as a table but i dont know the syntax for a pandas pivot. On the bus now so ill post some code when i get in

Thanks

Dimbo1979
  • 57
  • 1
  • 6
  • Are you using the Ipython notebook by chance? Then you can publish it as html from there. – firelynx Jul 15 '15 at 07:47
  • Hi firelynx -no i lm using it for a script at work that runs off a regular laptop. Basically it pulls info from a db, pivots it, does some calcs then i publish that on a html page so it needs to work outaide ipython – Dimbo1979 Jul 15 '15 at 07:50
  • Then the Ipython notebook (It's not a laptop, it's a web-server) may be very interesting to you. It's what most people who use pandas use to display reports. http://ipython.org/notebook.html You can also use the Ipython notebooks' extensions in a programmatic way, with the interactive part. – firelynx Jul 15 '15 at 08:02

1 Answers1

5

A pivot table is nothing else than a DataFrame, so it has the to_html() method described in the docs here

It will output html code for the table, for example, with this very simple dataframe:

In [1]: df
Out[1]:
    A   B
0   0   1
1   2   3

In [2]: print df.to_html()
Out[2]:

<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>A</th>
      <th>B</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0</td>
      <td>1</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2</td>
      <td>3</td>
    </tr>
  </tbody>
</table>
Random Nerd
  • 134
  • 1
  • 9
Julien Marrec
  • 11,605
  • 4
  • 46
  • 63