歡迎訪問我的專欄:
Python 處理文本是一項非常常見的功能,本文整理瞭多種文本提取及NLP相關的案例,還是非常用心的
文章很長,高低要忍一下,如果忍不瞭,那就收藏吧,總會用到的
- 提取 PDF 內容
- 提取 Word 內容
- 提取 Web 網頁內容
- 讀取 Json 數據
- 讀取 CSV 數據
- 刪除字符串中的標點符號
- 使用 NLTK 刪除停用詞
- 使用 TextBlob 更正拼寫
- 使用 NLTK 和 TextBlob 的詞標記化
- 使用 NLTK 提取句子單詞或短語的詞幹列表
- 使用 NLTK 進行句子或短語詞形還原
- 使用 NLTK 從文本文件中查找每個單詞的頻率
- 從語料庫中創建詞雲
- NLTK 詞法散佈圖
- 使用 countvectorizer 將文本轉換為數字
- 使用 TF-IDF 創建文檔術語矩陣
- 為給定句子生成 N-gram
- 使用帶有二元組的 sklearn CountVectorize 詞匯規范
- 使用 TextBlob 提取名詞短語
- 如何計算詞-詞共現矩陣
- 使用 TextBlob 進行情感分析
- 使用 Goslate 進行語言翻譯
- 使用 TextBlob 進行語言檢測和翻譯
- 使用 TextBlob 獲取定義和同義詞
- 使用 TextBlob 獲取反義詞列表
1提取 PDF 內容
# pip install PyPDF2 安裝 PyPDF2
import PyPDF2
from PyPDF2 import PdfFileReader
# Creating a pdf file object.
pdf = open("test.pdf", "rb")
# Creating pdf reader object.
pdf_reader = PyPDF2.PdfFileReader(pdf)
# Checking total number of pages in a pdf file.
print("Total number of Pages:", pdf_reader.numPages)
# Creating a page object.
page = pdf_reader.getPage(200)
# Extract data from a specific page number.
print(page.extractText())
# Closing the object.
pdf.close()