Python利用pdfplumber庫提取pdf中表格數(shù)據(jù)
一、pdfplumber庫是什么?
pdfplumber是一個(gè)用于從PDF文檔中提取文本和表格數(shù)據(jù)的Python庫。它可以幫助用戶輕松地從PDF文件中提取有用的信息,例如表格、文本、元數(shù)據(jù)等。pdfplumber庫的特點(diǎn)包括:簡(jiǎ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:
四、提取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', 'article']
['weixin_38093452', '空空 star', '130889268']
['weixin_38093452', '空空 star', '130852811']
['weixin_38093452', '空空 star', '130815851']
Process finished with exit code 0
到此這篇關(guān)于Python利用pdfplumber庫提取pdf中表格數(shù)據(jù)的文章就介紹到這了,更多相關(guān)Python提取pdf表格數(shù)據(jù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Python使用PyPDF2庫實(shí)現(xiàn)向PDF文件中插入內(nèi)容
- Python利用PyPDF2庫實(shí)現(xiàn)輕松提取PDF文本
- Python使用PyPDF2?Pillow庫來將PDF文件轉(zhuǎn)圖片
- PyPDF2讀取PDF文件內(nèi)容保存到本地TXT實(shí)例
- 解決pyPdf和pyPdf2在合并pdf時(shí)出現(xiàn)異常的問題
- Python實(shí)現(xiàn)PyPDF2處理PDF文件的方法示例
- Python中使用pypdf2合并、分割、加密pdf文件的代碼詳解
- Python使用pdfplumber庫高效解析PDF文件
- python用pdfplumber提取pdf表格數(shù)據(jù)并保存到excel文件中
- Python利用pdfplumber實(shí)現(xiàn)讀取PDF寫入Excel
- python使用PyPDF2 和 pdfplumber操作PDF文件
相關(guān)文章
Python實(shí)現(xiàn)批量識(shí)別圖片文字并存為Excel
批量文字識(shí)別是Python辦公自動(dòng)化的基本操作,應(yīng)用在我們工作生活中的方方面面。本文主要以開源免費(fèi)的easyocr來實(shí)現(xiàn)批量識(shí)別圖片文字并存為Excel,感興趣的可以學(xué)習(xí)一下2022-06-06基于Python函數(shù)的作用域規(guī)則和閉包(詳解)
下面小編就為大家分享一篇基于Python函數(shù)的作用域規(guī)則和閉包詳解,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2017-11-11windows系統(tǒng)多個(gè)python中更改默認(rèn)python版本
這篇文章主要給大家介紹了關(guān)于windows系統(tǒng)多個(gè)python中更改默認(rèn)python版本的相關(guān)資料,在Python開發(fā)中,不同的項(xiàng)目往往需要使用不同的Python版本,需要的朋友可以參考下2023-09-09PyQt5 實(shí)現(xiàn)狀態(tài)欄永久顯示消息
這篇文章主要介紹了PyQt5 實(shí)現(xiàn)狀態(tài)欄永久顯示消息的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-03-03python?random模塊常用函數(shù)基礎(chǔ)教程
這篇文章主要為大家介紹了python?random模塊常用函數(shù)基礎(chǔ)教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06Python中字符串轉(zhuǎn)換為列表的常用方法總結(jié)
本文將詳細(xì)介紹Python中將字符串轉(zhuǎn)換為列表的八種常用方法,每種方法都具有其獨(dú)特的用途和適用場(chǎng)景,文中的示例代碼講解詳細(xì),感興趣的可以了解下2023-11-11