본문 바로가기

python

(197)
Chinese Character WordCloud Python Code>from wordcloud import WordCloud from matplotlib import pyplot from collections import Counter from PIL import Image import numpy text = '' with open("데이터위치", encoding="utf-8") as f: text = f.read(); tmp = list(text) hanja = [] ignore = [" ", "\n", ",", ".", "(", ")", "\U000f0703", "\ufeff"] for item in tmp: if item not in ignore: hanja.append(item.strip()) count = Counter(hanja) most..
KoNLpy Korean WordCloud Code>from wordcloud import WordCloud from matplotlib import pyplot from collections import Counter from konlpy.tag import Okt text = '' with open("파일경로", encoding="utf-8") as f: text = f.read() nlp = Okt() nouns = nlp.nouns(text) words = [] for n in nouns: if len(n) > 1: words.append(n) count = Counter(words) most = count.most_common(100) tags = {} for n, c in most: tags[n] = c wc = WordCloud(ba..
KoNLpy KoNLpy는 한글 형태소 분석에 쓰이는 오픈소스이다. KoNLpy를 Windows에서 사용할려면 두가지 전제 조건이 필요하다. 1. JAVA 개발환경 설치 2. C++ 개발환경 설치 JAVA 환경은 https://developer-ankiwoong.tistory.com/108를 참조한다. C++ 환경은 Microsoft Visual C++ Build Tools를 사용하는데 버전이 여러개 존재하나 KoNLpy를 사용할려면 14.0.25420.1을 사용하면 된다. 위에 두가지 환경을 다 설치 하였다면 이제 KoNLpy를 설치 하면 된다. 1. 시작 > 실행 > 명령 프롬프트 2. pip install konlpy 설치 에러시 JAVA 환경 설정 또는 Visual C++ Tools에 버전이 안맞아 발생하는 ..
KoNLpy JAVA Environment Variable Error Dissolvent 1. 자바 개발 환경 설치 여부 확인 1-1. 시작 > 실행 > 명령 프롬프트 1-2. javac -version 1-3. JAVA 버전이 나오는지 확인한다. 에러 창이 뜰 시 설치가 안되있는 경우이다. 2. JAVA 개발 환경 설치 2-1. 구글에 jdk-8u181-windows-x64를 검색하여 설치한다. 3. JAVA 개발 환경 변수 설정 3-1. 제어판 > 모든 제어판 항목 > 시스템 > 고급 시스템 설정 3-2. 환경변수 3-3. 시스템 변수 > 새로 만들기 3-3-1. 변수이름 : JAVA_HOME / 변수 값 : C:\Program Files\Java\jdk1.8.0_181 3-4. 시스템 변수 > Path > 편집 > 새로만들기 3-4-1. %JAVA_HOME%bin 4. 시스템 재시작
WordCloud Font HSL Color Code 1>from wordcloud import WordCloud from matplotlib import pyplot def make_colors(word, font_size, position, orientation, random_state, **kwargs): color = "hsl Color Code" return color text = '' with open("파일경로", encoding="utf-8") as f: text = f.read() wc = WordCloud(width=1200, height=800, scale=2.0, max_font_size=150, background_color="#ffffff") gen = wc.generate(text) recolor = gen.recolor..
WordCloud Font RGB Color Code 1>from wordcloud import WordCloud from matplotlib import pyplot def make_colors(word, font_size, position, orientation, random_state, **kwargs): color = "rgb(0, 0, 0)" return color text = '' with open("파일경로명", encoding="utf-8") as f: text = f.read() wc = WordCloud(width=1200, height=800, scale=2.0, max_font_size=150, background_color="#ffffff") gen = wc.generate(text) recolor = gen.recolor(..
WordCloud Font Single Hex Color Code>from wordcloud import WordCloud from matplotlib import pyplot def make_colors(word, font_size, position, orientation, random_state, **kwargs): color = "Hex Color Code" return color text = '' with open("파일경로", encoding="utf-8") as f: text = f.read() wc = WordCloud(width=1200, height=800, scale=2.0, max_font_size=150, background_color="#ffffff") gen = wc.generate(text) recolor = gen.recolor(c..
WordCloud Option Background image Code>from PIL import Image import numpy img = Image.open("배경화면경로"); img_array = numpy.array(img) wc = WordCloud(width=600, height=1200, max_font_size=150, scale=2.0, max_words=100, stopwords=ignore, mask=img_array)White Background Code>background_color="white" 정리>Numpy 모듈이 적용된 이미지를 로드하여 배열로 변환 한뒤 사용한다.보통 배경 이미지를 가져와서 출력을 할려면 배경은 흰색 해당 그림은 검은색이 적용된 이미지를 가져와야된다.투명도가 지정된 이미지는 출력이 정상적으로 이루어지지 않는다.또한..