wuwucat
wuwucat

Reputation: 2621

save pandas' to_html' as a file

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.

Upvotes: 12

Views: 20974

Answers (3)

Abbas
Abbas

Reputation: 4069

As of the current version of pandas tsod.to_html('out.html') works fine.

Upvotes: 5

danodonovan
danodonovan

Reputation: 20373

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)

Upvotes: 21

wuwucat
wuwucat

Reputation: 2621

a=tsod.to_html()
save(a,'path')

will work

Upvotes: -2

Related Questions