टेक्स्ट डेटा की सफाई
अब जब आपने stopwords और punctuations परिभाषित कर लिए हैं, तो आइए इन्हें इस्तेमाल करके dataframe df में हमारी enron emails की सफाई आगे बढ़ाते हैं। stopwords और punctuations वाली सूचियाँ क्रमशः stop और exclude के तहत उपलब्ध हैं। पूरी तरह साफ डेटा पाने से पहले कुछ और कदम बाकी हैं, जैसे शब्दों का "lemmatization" और क्रियाओं का stemming। ईमेल डेटा में क्रियाएँ पहले से stemmed हैं, और इस अभ्यास में lemmatization भी आपके लिए कर दिया गया है।
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Fraud Detection
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Import the lemmatizer from nltk
from nltk.stem.wordnet import WordNetLemmatizer
lemma = WordNetLemmatizer()
# Define word cleaning function
def clean(text, stop):
text = text.____()
# Remove stopwords
stop_free = " ".join([word for word in text.lower().split() if ((___ not in ___) and (not word.isdigit()))])
# Remove punctuations
punc_free = ''.join(word for word in stop_free if ___ not in ____)
# Lemmatize all words
normalized = " ".join(____.____(word) for word in punc_free.split())
return normalized