채용공고 워드클라우드

IngCoding·2022년 2월 24일
1

시각화 (워드클라우드)

코드

# 워드클라우드 IMPORT

import matplotlib.pyplot as mpl # 시각화
from konlpy.tag import Okt # 형태소분석기 : Openkoreatext
from collections import Counter # 빈도 수 세기
from wordcloud import WordCloud, STOPWORDS # wordcloud 만들기

# 한글폰트 설정 
mpl.rcParams['font.family'] = 'Malgun Gothic'
mpl.rcParams['font.size'] = 20
mpl.rcParams['axes.unicode_minus'] = False    # 마이너스 깨짐 방

# 텍스트 불러오기 (채용공고를 txt 파일로 저장)
text = open('word.txt', encoding='utf-8-sig').read()

# 형태소 분석기를 통해 명사만 추출하는 함수
def token_konlpy(text):
    okt=Okt()
    return [word for word in okt.nouns(text) if len(word)>1] # 1글자 명사는 제외    

noun = token_konlpy(text)
len(noun)

noun_set = set(noun) # 중복값 제거
                    # stopwords 변수 만들어서, 차집합으로 빼기 
len(noun_set)

# 텍스트 파일로 저장
f = open('noun_set.txt','w', encoding='utf-8')
f.write(str(noun_set))
f.close()

# 추출된 명사들의 빈도수 카운트 
count = Counter(noun)
count.pop('코드') # 회사, 업종, 업무 지칭하는 단어 제외
count.pop('스테이')
count.pop('교육')
count.pop('업무')
count.pop('코스')
count.pop('운영')
count.pop('기반')
count.pop('위해')
count.pop('부트캠프')

len(count)

# 빈도수 상위 10개 까지 딕셔너리 형태로 자료 변환 {'noun':'key'}
word = dict(count.most_common(10))

#wordcloud 만들기
wc = WordCloud(max_font_size=200, font_path = 'C:\Windows\Fonts\malgun.ttf',background_color="white",width=2000, height=500).generate_from_frequencies(word) # font 경로 개별적으로 설정해야함

mpl.figure(figsize = (40,40))
mpl.imshow(wc)
mpl.tight_layout(pad=0)
mpl.axis('off')
mpl.show()
word # 상위 10개 단어 반복횟수
{'데이터': 7,
 '학습': 7,
 '수강생': 5,
 '분석': 3,
 '취업': 3,
 '입학': 3,
 '과정': 3,
 '경험': 3,
 '연구': 2,
 '인재': 2}
profile
Data & PM

0개의 댓글