- Python 資料科學教程
- Python 資料科學 - 首頁
- Python 資料科學 - 入門
- Python 資料科學 - 環境設定
- Python 資料科學 - Pandas
- Python 資料科學 - Numpy
- Python 資料科學 - SciPy
- Python 資料科學 - Matplotlib
- Python 資料處理
- Python 資料操作
- Python 資料清洗
- Python 處理 CSV 資料
- Python 處理 JSON 資料
- Python 處理 XLS 資料
- Python 關係型資料庫
- Python NoSQL 資料庫
- Python 日期和時間
- Python 資料整理
- Python 資料聚合
- Python 讀取 HTML 頁面
- Python 處理非結構化資料
- Python 詞彙標記化
- Python 詞幹提取和詞形還原
- Python 資料視覺化
- Python 圖表屬性
- Python 圖表樣式
- Python 箱線圖
- Python 熱力圖
- Python 散點圖
- Python 氣泡圖
- Python 3D 圖表
- Python 時間序列
- Python 地理資料
- Python 圖資料
Python 詞彙標記化
詞彙標記化是將大段文字分割成單詞的過程。這是自然語言處理任務中的一個要求,其中需要捕獲每個單詞並進行進一步分析,例如對特定情感進行分類和計數等。自然語言工具包 (NLTK) 是用於實現此目的的庫。在繼續進行 Python 詞彙標記化程式之前,請安裝 NLTK。
conda install -c anaconda nltk
接下來,我們使用word_tokenize方法將段落分割成單個單詞。
import nltk word_data = "It originated from the idea that there are readers who prefer learning new skills from the comforts of their drawing rooms" nltk_tokens = nltk.word_tokenize(word_data) print (nltk_tokens)
執行上述程式碼時,會產生以下結果。
['It', 'originated', 'from', 'the', 'idea', 'that', 'there', 'are', 'readers', 'who', 'prefer', 'learning', 'new', 'skills', 'from', 'the', 'comforts', 'of', 'their', 'drawing', 'rooms']
句子標記化
我們還可以像標記化單詞一樣標記化段落中的句子。我們使用sent_tokenize方法來實現此目的。下面是一個例子。
import nltk sentence_data = "Sun rises in the east. Sun sets in the west." nltk_tokens = nltk.sent_tokenize(sentence_data) print (nltk_tokens)
執行上述程式碼時,會產生以下結果。
['Sun rises in the east.', 'Sun sets in the west.']
廣告