使用Python将Pandas DataFrame导出为PDF文件 [英] Export Pandas DataFrame into a PDF file using Python

查看:1106
本文介绍了使用Python将Pandas DataFrame导出为PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为熊猫中的数据框生成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/package/markdown-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/).您可以在其中使用扩展名,搜索降价为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()时,由于某种原因,我不得不删除多余的'\ n'字符.我选择使用Atom -> Find -> '\n' -> Replace "".

Note: When using to_html() recently I had to remove extra '\n' characters for some reason. I chose to use Atom -> Find -> '\n' -> Replace "".

总体来说应该可以解决问题!

Overall this should do the trick!

这篇关于使用Python将Pandas DataFrame导出为PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆