pandas 将熊猫的 to_html 保存为文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14897833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
save pandas' to_html' as a file
提问by wuwucat
I have a DateFrame 'tsod', now I convert it to html:
我有一个 DateFrame 'tsod',现在我将它转换为 html:
tsod.to_html()
How can I save this as a file? better save as a '.html' file.
如何将其保存为文件?最好另存为“.html”文件。
回答by danodonovan
with open('my_file.html', 'w') as fo:
fo.write(tsod.to_html())
or alternatively using pandas
或者使用Pandas
tsod.to_html(open('my_file.html', 'w'))
or again (thanks @andy-hayden)
或者再次(感谢@andy-hayden)
with open('my_file.html', 'w') as fo:
tsod.to_html(fo)
回答by Abbas
As of the current version of pandas tsod.to_html('out.html')works fine.
截至当前版本的Pandastsod.to_html('out.html')工作正常。
回答by wuwucat
a=tsod.to_html()
save(a,'path')
will work
将工作

