Python使用Camelot从PDF中精准获取表格数据
前言-为什么pdf表格数据提取如此重要在数据分析与业务智能领域,pdf文档中的表格数据是一座巨大的"金矿",却因其封闭格式成为数据从业者的"噩梦"。从企业财报到
plumber_tables = plumber_page.extract_tables() print(f"检测到 {len(plumber_tables)} 个表格") if len(plumber_tables) > 0: plumber_table = plumber_tables[0] plumber_df = pd.dataframe(plumber_table[1:], columns=plumber_table[0]) print(f"表格维度: {plumber_df.shape}") print("\n表格预览:") print(plumber_df.head().to_string()) else: print(f"页码 {page} 超出范围") except exception as e: print(f"pdfplumber提取出错: {str(e)}") print("\n===== camelot提取结果 =====") try: # 使用camelot提取表格 camelot_tables = camelot.read_pdf(pdf_path, pages=str(page+1)) # camelot页码从1开始 print(f"检测到 {len(camelot_tables)} 个表格") if len(camelot_tables) > 0: camelot_df = camelot_tables[0].df print(f"表格维度: {camelot_df.shape}") print(f"准确度: {camelot_tables[0].accuracy}") print("\n表格预览:") print(camelot_df.head().to_string()) except exception as e: print(f"camelot提取出错: {str(e)}") return none# 使用示例compare_with_pdfplumber("annual_report.pdf")
相关文章:
-
前言python的os模块(operating system)是提供给用户来与操作系统进行交互的内置库,可以用来进行文件和目录的管理操作。它提供了一系列函数,允许你创建、删除、重命…
-
-
-
前言如果你下载玩完python之后对python对它有了一定的了解,想要下载一些有趣的或者要用到的库比如pygame,pymysql等,那么就避免不了要使用python的自带的包下…
-
-
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论