시작하기무료로 시작하기

텍스트 데이터 정제

이제 불용어와 구두점을 정의했으니, 이를 활용해 데이터프레임 dfEnron 이메일을 더 깨끗하게 정제해 보겠습니다. 불용어와 구두점 목록은 각각 stopexclude에 들어 있습니다. 정제를 마치기 전 해야 할 작업이 몇 가지 더 있는데, 단어 “표제어 추출(lemmatization)”동사 어간 추출(stemming) 등이 있습니다. 이메일 데이터의 동사는 이미 어간 추출이 되어 있고, 이번 연습 문제에서는 표제어 추출도 미리 적용해 두었습니다.

이 연습은 강의의 일부입니다

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
코드 편집 및 실행