Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

save pandas' to_html' as a file

Tags:

python

pandas

I have a DateFrame 'tsod', now I convert it to html:

tsod.to_html()

How can I save this as a file? better save as a '.html' file.

like image 538
wuwucat Avatar asked Feb 15 '13 15:02

wuwucat


People also ask

How do I save DataFrame as HTML in Python?

Use the to_html() Method to Save a Pandas DataFrame as HTML File. In the following code, we have the students' data. We converted the Pandas dataframe to HTML using the method to_html() available in the pandas library.

What is a panda file?

Pandas is a powerful and flexible Python package that allows you to work with labeled and time series data. It also provides statistics methods, enables plotting, and more. One crucial feature of Pandas is its ability to write and read Excel, CSV, and many other types of files.


1 Answers

with open('my_file.html', 'w') as fo:
    fo.write(tsod.to_html())

or alternatively using pandas

tsod.to_html(open('my_file.html', 'w'))

or again (thanks @andy-hayden)

with open('my_file.html', 'w') as fo:
    tsod.to_html(fo)
like image 94
danodonovan Avatar answered Oct 01 '22 03:10

danodonovan