【发布时间】:2017-10-13 08:46:52
【问题描述】:
我发现了一种将pandas here 生成的表格导出为 PDF 的好方法,关于将其转换为 png 文件的部分对我来说并不感兴趣。
问题是,我收到以下错误消息:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-10-9818a71c26bb> in <module>()
13
14 with open(filename, 'wb') as f:
---> 15 f.write(template.format(z.to_latex()))
16
17 subprocess.call(['pdflatex', filename])
TypeError: a bytes-like object is required, not 'str'
我一开始并没有真正理解代码,这使得纠正错误非常困难。我的代码如下所示:
import subprocess
filename = 'out.tex'
pdffile = 'out.pdf'
template = r'''\documentclass[preview]{{standalone}}
\usepackage{{booktabs}}
\begin{{document}}
{}
\end{{document}}
'''
with open(filename, 'wb') as f:
f.write(template.format(z.to_latex()))
subprocess.call(['pdflatex', filename])
其中z 是使用pandas 生成的DataFrame。
希望有人能帮忙。 先感谢您, 西托。
【问题讨论】: