【发布时间】:2013-01-31 14:42:36
【问题描述】:
我有一个 DateFrame 'tsod',现在我将其转换为 html:
tsod.to_html()
如何将其保存为文件?最好保存为“.html”文件。
【问题讨论】:
我有一个 DateFrame 'tsod',现在我将其转换为 html:
tsod.to_html()
如何将其保存为文件?最好保存为“.html”文件。
【问题讨论】:
with open('my_file.html', 'w') as fo:
fo.write(tsod.to_html())
或者使用熊猫
tsod.to_html(open('my_file.html', 'w'))
或再次(感谢@andy-hayden)
with open('my_file.html', 'w') as fo:
tsod.to_html(fo)
【讨论】:
tsod.to_html('my_file.html') 不会起作用。 to_html 不接受字符串,它接受可以写入的内容,无论是打开的文件还是 StringIO 缓冲区(它会查找 .write())。不过,您可以使用tsod.to_html(fo)。
tsod.to_html(fo).
to_html 现在确实接受了字符串,所以将其命名为 tsod.to_html('Name.html')。
a=tsod.to_html()
save(a,'path')
会起作用
【讨论】:
save()?这不是 python 内置函数 - 提示,请尝试添加 import 语句。
截至当前版本的 pandas tsod.to_html('out.html') 工作正常。
【讨论】: