提取pdf文件中的表格数据原文链接
/blog//08/how-to-extract-tabular-data-from-pdf-document-using-camelot-in-python/
另外还参考了这篇文章
https://camelot-py.readthedocs.io/en/master/
实现提取pdf文档中的表格数据需要使用camelot模块
这个模块可以直接使用pip进行安装
pipinstall"camelot-py[cv]"
用到的pdf示例文件可以直接在原文链接处下载
http://gstcouncil.gov.in/sites/default/files/gst-revenue-collection-march.pdf
第一步是读入pdf文件
tables=camelot.read_pdf('gst-revenue-collection-march.pdf',flavor='stream',pages='0-3')importcamelot
这里flavor
参数的作用暂时还不知道
如果表格跨页需要指定pages参数
tables[2] tables[2].dftables
tables可以返回解析获得的表格数量
tables[2]获取指定的表格
tables[2].df将表格数据转换成数据框
pandas 中两个数据框按照行合并需要用到append()方法
bb={"A":[4],"B":[7]} importpandasaspd a=pd.DataFrame(aa) b=pd.DataFrame(bb) a.append(b)aa={"A":[1,2,3],"B":[4,5,6]}
SVG格式转换为pdf格式原文链接
/a-simple-guide-to-python-convert-svg-to-pdf-with-svglib-python-tutorial/
实现这个功能需要使用到的是svglib这个库,直接使用pip安装
pipinstallsvglib
svg转换为pdf格式代码
fromreportlab.graphicsimportrenderPDF drawing=svg2rlg("home.svg") renderPDF.drawToFile(drawing,"file.pdf")fromsvglib.svglibimportsvg2rlg
欢迎大家关注我的公众号
小明的数据分析笔记本