【发布时间】:2022-01-25 12:03:05
【问题描述】:
我正在尝试从 pdf 文件中提取数据并将其转换为 pandas 数据框 我使用 Pymupdf 模块中的“fitz”来提取数据。 然后用 pandas 将其转换为数据框
from pathlib import Path
# returns all file paths that has .pdf as extension in the specified directory
pdf_search = Path("C:/Users/Ayesha.Gondekar/Eversana-CVs/").glob("*.pdf")
# convert the glob generator out put to list
# skip this if you are comfortable with generators and pathlib
pdf_files = pdf_files = [str(file.absolute()) for file in pdf_search]
#数据提取代码:
for pdf in pdf_files:
with fitz.open(pdf) as doc:
pypdf_text = ""
for page in doc:
pypdf_text += page.getText()
上面的代码只是提取文件夹中最后一个pdf的数据。从而仅给出该pdf的结果
但同样,我有一个包含许多 pdf 文档的文件夹。我的目标是从文件夹中逐个读取每个pdf文件并进行文本提取,然后将其转换为数据框。 我如何在 python 中做到这一点?
【问题讨论】: