使用 Python 将 Pandas DataFrame 导出为 PDF 文件 [英] Export Pandas DataFrame into a PDF file using Python
问题描述
为 Pandas 中的数据框生成 PDF 的有效方法是什么?
What is an efficient way to generate PDF for data frames in Pandas?
推荐答案
嗯,一种方法是使用 Markdown.您可以使用 df.to_html()
.这会将数据框转换为 html 表.从那里你可以将生成的 html 放入一个 Markdown 文件 (.md)(参见 http://daringfireball.net/projects/markdown/basics).从那里,有一些实用程序可以将 Markdown 转换为 pdf(https://www.npmjs.com/包/降价-pdf).
Well one way is to use markdown. You can use df.to_html()
. This converts the dataframe into a html table. From there you can put the generated html into a markdown file (.md) (see http://daringfireball.net/projects/markdown/basics). From there, there are utilities to convert markdown into a pdf (https://www.npmjs.com/package/markdown-pdf).
此方法的一个多合一工具是使用 Atom 文本编辑器 (https://atom.io/一>).在那里你可以使用一个扩展,搜索markdown to pdf",这将为你进行转换.
One all-in-one tool for this method is to use Atom text editor (https://atom.io/). There you can use an extension, search "markdown to pdf", which will make the conversion for you.
注意:最近在使用 to_html()
时,由于某种原因我不得不删除额外的 '
' 字符.我选择使用 Atom ->查找 ->'
' ->替换"
.
Note: When using to_html()
recently I had to remove extra '
' characters for some reason. I chose to use Atom -> Find -> '
' -> Replace ""
.
总的来说,这应该可以解决问题!
Overall this should do the trick!
这篇关于使用 Python 将 Pandas DataFrame 导出为 PDF 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!