前言
大家好,我是空空star,本篇給大家分享一下
《通過Python的pdfplumber庫提取pdf中表格數(shù)據(jù)》
。
一、pdfplumber庫是什么?
pdfplumber是一個(gè)用于從PDF文檔中提取文本和表格數(shù)據(jù)的Python庫。它可以幫助用戶輕松地從PDF文件中提取有用的信息,例如表格、文本、元數(shù)據(jù)等。pdfplumber庫的特點(diǎn)包括:簡單易用、速度快、支持多種PDF文件格式、支持從多個(gè)頁面中提取數(shù)據(jù)等。pdfplumber庫還提供了一些方便的方法來處理提取的數(shù)據(jù),例如排序、過濾和格式化等。它是一個(gè)非常有用的工具,特別是在需要從大量PDF文件中提取數(shù)據(jù)時(shí)。
二、安裝pdfplumber庫
pip install pdfplumber
三、查看pdfplumber庫版本
pip show pdfplumber
Name: pdfplumber
Version: 0.9.0
Summary: Plumb a PDF for detailed information about each char, rectangle, and line.
Home-page: https://github.com/jsvine/pdfplumber
Author: Jeremy Singer-Vine
Author-email: jsvine@gmail.com
License:
Requires: pdfminer.six, Pillow, Wand
Required-by:文章來源:http://www.zghlxwxcb.cn/news/detail-462573.html
四、提取pdf中表格數(shù)據(jù)
1.引入庫
import pdfplumber
2.定義pdf文件路徑
local = '/Users/kkstar/Downloads/'
3.打開pdf文件
with pdfplumber.open(local+"demo_table.pdf") as pdf:

4.獲取pdf文件中的頁數(shù)
num_pages = len(pdf.pages)
5.遍歷每一頁
for page_num in range(num_pages):
6.獲取當(dāng)前頁內(nèi)容
page = pdf.pages[page_num]
7.提取表格數(shù)據(jù)
table = page.extract_table(table_settings={
"vertical_strategy": "lines",
"horizontal_strategy": "lines",
"intersection_x_tolerance": 15,
"intersection_y_tolerance": 15
})
8.輸出表格數(shù)據(jù)
for row in table:
print(row)
9.效果
[‘username’, ‘nickname’, ‘a(chǎn)rticle’]
[‘weixin_38093452’, ‘空空 star’, ‘130889268’]
[‘weixin_38093452’, ‘空空 star’, ‘130852811’]
[‘weixin_38093452’, ‘空空 star’, ‘130815851’]
Process finished with exit code 0文章來源地址http://www.zghlxwxcb.cn/news/detail-462573.html
總結(jié)
到了這里,關(guān)于通過Python的pdfplumber庫提取pdf中表格數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!