移除停用詞
在接下來的練習中,你要先把 Enron 電子郵件做清理,才能把這些資料用在主題模型上。文字清理不太容易,因此你會學到一些實用步驟。包含郵件的資料框 df 已可使用。第一步,你需要定義要在下一個練習從文字資料中移除的停用詞與標點符號清單。來試試看吧。
本練習屬於課程
Fraud Detection in Python
練習說明
- 從
ntlk匯入停用詞(stopwords)。 - 以 'english' 作為停用詞語系,指定給變數
stop。 - 從
string套件取得標點符號集合,指定給exclude。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import nltk packages and string
from nltk.corpus import ____
import string
# Define stopwords to exclude
stop = set(____.____('____'))
stop.update(("to","cc","subject","http","from","sent", "ect", "u", "fwd", "www", "com"))
# Define punctuations to exclude and lemmatizer
exclude = set(____.____)