Python Pandas Data Frame save as HTML page

I am trying to save defined in Python Pandas Data Frame as HTML page. In addition i would like to make this table saved as HTML table ability to be filtered by value of any column. Can you please provide possible solution? At the final this should be table saved as HTML page. I would like to incorporate this code in my Python code. Thank you


You can use pandas.DataFrame.to_html().

>>> import numpy as np
>>> from pandas import *
>>> df = DataFrame({'foo1' : np.random.randn(2),
                    'foo2' : np.random.randn(2)})
>>> df.to_html('filename.html')

This will save the following html to filename.html.


<table border="1" class="dataframe">
    <tr style="text-align: right;">

.to_html() also can be used to create html string

import io
import pandas as pd
from numpy.random import randn

df = pd.DataFrame(
    randn(5, 4),
    index = 'A B C D E'.split(),
    columns = 'W X Y Z'.split()

str_io = io.StringIO()

df.to_html(buf=str_io, classes='table table-striped')

html_str = str_io.getvalue()


<table border="1" class="dataframe table table-striped">
    <tr style="text-align: right;">

Need Your Help

What is Linux utility to mangle a C++ symbol name?

c++ compiler-construction dlsym demangler

I have c++filt command to demangle a symbol, what is the tool to do the opposite and mangle a symbol name?

NetworkOnMainThreadException on Facebook Login with Phonegap 1.6.0

facebook exception cordova networkonmainthread

I am currently creating an application using Phonegap 1.6.0 and Sencha Touch 1.1. Recently, when testing on a smartphone with Android 4.0.4, we discovered that the Facebook Login doesn't quite work...