자연어 처리 중 키워드의 출현빈도 및 자주 등장한 키워드에 대한 나열이 가능합니다.

 

collection 라이브러리에 Counter 패키지 사용하였습니다.

 

코드는 아래와 같습니다.

from collections import Counter #라이브러리 호출

df['noun'] = df['content'].apply(lambda x : mecab.nouns(x)) #데이터프레임 본문에서 명사만 추출

#전처리(불용어 제거 및 텍스트 정제)
noun = df['noun'].apply(lambda x : [item for item in x if item not in stop_words])
noun = noun.apply(lambda x : [word for word in x if len(word) > 1])

#counter 함수를 사용하기위해 list화 
noun_list = []

for tokens in noun:
    for token in tokens:
        noun_list.append(token)

#키워드 빈도수 확인
noun_count = Counter(noun_list)
#상위 50개 추출
noun_50 = noun_count.most_common(50)

 

+ Recent posts