将pandas的"to_html"另存为文件 [英] save pandas' to_html' as a file

查看:67
本文介绍了将pandas的"to_html"另存为文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DateFrame'tsod',现在我将其转换为html:

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

tsod.to_html()

如何将其另存为文件?最好另存为".html"文件.

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

推荐答案

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

或使用熊猫

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

或再次(感谢@ andy-hayden)

or again (thanks @andy-hayden)

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

这篇关于将pandas的"to_html"另存为文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆