首页 > 解决方案 > 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。

任何帮助都是极好的。

谢谢

标签: pythonpandasgoogle-colaboratory

解决方案


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'>

推荐阅读