เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การทำความสะอาดข้อมูลข้อความ

เมื่อกำหนด stopwords และเครื่องหมายวรรคตอน แล้ว มาใช้สิ่งเหล่านี้เพื่อ ทำความสะอาดอีเมล Enron ใน dataframe df ต่อไป รายการที่เก็บ stopwords และเครื่องหมายวรรคตอนอยู่ใน stop และ exclude ตามลำดับ ยังมีขั้นตอนเพิ่มเติมอีกสองสามอย่างก่อนที่ข้อมูลจะสะอาดสมบูรณ์ เช่น "lemmatization" ของคำ และ stemming คำกริยา โดยคำกริยาในข้อมูลอีเมลได้รับการ stemming แล้ว และ lemmatization ก็ทำให้เรียบร้อยแล้วในแบบฝึกหัดนี้

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การตรวจจับการฉ้อโกงด้วย Python

ดูคอร์ส

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# 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
แก้ไขและรันโค้ด