python - PDF 到 Pandas 数据框
问题描述
就在我认为我终于得到它的时候,这样一个新手。
我正在尝试从 PDF 表格的列中获取数字列表。
第一步我想转换为 Panda DF。
pip install tabula-py
pip install PyPDF2
import pandas as pd
import tabula
df = tabula.read_pdf('/content/Manifest.pdf')
然而,我得到的输出是 1 的列表,而不是 DF。当我查看 DF 信息时,我只是不知道如何访问它,因为它是 1 的列表。
所以不知道为什么我没有得到一个 DF,也不知道我打算用 1 的列表做什么。输出
不确定这是否重要,但我正在使用谷歌 Colab。
任何帮助都是极好的。
谢谢
解决方案
tabula.read_pdf 返回没有任何附加参数的数据帧列表。要访问您的特定数据框,您可以选择索引并使用它。
这是一个示例,我已阅读文档并选择了第一个索引并比较了类型
import tabula
df = tabula.read_pdf(
"https://github.com/chezou/tabula-py/raw/master/tests/resources/data.pdf")
df_0 = df[0]
print("type of df :", type(df))
print("type of df_0", type(df_0))
回报:
type of df : <class 'list'>
type of df_0 <class 'pandas.core.frame.DataFrame'>
推荐阅读
- symfony - Symfony 用户实体(PhpStorm 警告)
- visual-studio-code - VS Code 调试疯狂
- kotlin - Kotlin 中的数学规则
- node.js - 使用 nodejs 从 Azure Keyvault 获取 Secret
- python - 宽度不等的“矩阵” - 循环的有效方法
- excel - Excel宏根据单元格值乘以行
- java - Java junit4有序测试方法运行
- python - Python 3.5+ 中类型提示的动态检查
- swift - Swift:将数据从 Firestore 获取到数组中的问题
- html - 如何删除标签和输入之间的额外空间?