-
Notifications
You must be signed in to change notification settings - Fork 0
/
RO_wordcloud.py
65 lines (51 loc) · 1.98 KB
/
RO_wordcloud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#from fastapi import FastAPI
from wordcloud import WordCloud
from collections import Counter
from konlpy.tag import Okt
from PIL import Image
import numpy as np
import pandas as pd
# app = FastAPI()
# @app.get("/RO_wordcloud")
def RO_wordcloud() :
RO_df = pd.read_csv("RO_Data.csv", encoding='utf-8-sig')
text = ''
for i in range(RO_df.shape[0]) :
text+=RO_df['special_note'][i]
okt = Okt()
nouns = okt.nouns(text) # 명사만 추출
words = [n for n in nouns if len(n) > 1] # 단어의 길이가 1개인 것은 제외
words_processing = words
for j in range(len(words)-1):
try :
if words[j] == '전' and words[j+1] == '좌석':
words_processing.pop(j)
words_processing.insert(j,'전좌석')
words_processing.pop(j+1)
j=j+1
if words[j] == '보조' and words[j+1] == '석':
words_processing.pop(j)
words_processing.insert(j,'보조석')
words_processing.pop(j+1)
j=j+1
if words[j] == '운전' and words[j+1] == '석':
words_processing.pop(j)
words_processing.insert(j,'운전석')
words_processing.pop(j+1)
j=j+1
if words[j] == '조' and words[j+1] == '수석':
words_processing.pop(j)
words_processing.insert(j,'조수석')
words_processing.pop(j+1)
j=j+1
if words[j] == '수석':
words_processing.pop(j)
words_processing.insert(j,'조수석')
words_processing.pop(j+1)
j=j+1
except :
break
c = Counter(words_processing) # 단어별 빈도수 형태의 딕셔너리 데이터 : DB저장
print("c : " , c)
return {"1" : 1}
RO_wordcloud()