1
我发现使用pandas
here将生成的表格导出为PDF格式的相当不错的方法,但将其转换为PNG文件的部分对我来说是无趣的。将pandas表格导出为pdf
的问题是,我得到了以下错误消息:
---------------------------------------------------------------------------
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
。
希望有人可以帮忙。 预先感谢您, Sito。