728x90
삼성 QLED TV 아마존 고객 리뷰 분석하기
아래에서 추출한 삼성 QLED TV 아마존 리뷰를 갖고 와서 파이썬으로 텍스트 분석해보도록 하겠다. 텍스트 마이닝이 조금 어려운 파트라 파이썬으로 많이 해보지 않았지만 이번 포스팅 작성을 위해 조금 스터디를 했다. 아래 코드를 보시면서 조금 이상하거나 비효율적인 부분이 있더라도 이해해주기 바란다.
2020/11/03 - [문송충의 코딩하기/파이썬 데이터 분석] - [파이썬] - 아마존에서 삼성 QLED TV 고객 리뷰 크롤링해서 가져오기
데이터 전처리
우선 리뷰 중에서는 오로지 영어문자만을 남겨놓고, 대문자는 소문자로 다 변환하겠다.
import pandas as pd
import re
df=pd.read_csv('C:/Users/동섭/삼성TV 아마존 리뷰.csv')
df['body2']=df['Body'].apply(lambda x: re.sub('[^a-zA-Z]', ' ', x).lower())
다음으로는 의미가 없어 보이는 불용어를 제거하도록 하겠다. nltk 패키지 내 word_tokenize와 Stopwords 패키지를 사용하면 리뷰에 있는 무의미한 단어를 제거할 수 있다.
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
stop_words = set(stopwords.words('english'))
df['Words']=df['body2'].apply(lambda x: word_tokenize(x))
tokens=[]
for words in df['Words']:
for i in words:
if i not in stop_words and len(i) >1 and i != 'go' and i != 'tv' :
tokens.append(i)
real_words=[]
lens=['samsung','one','see','would','use','well','using','get','also','set','new','really','like','good','even']
for t in tokens:
if t not in lens :
real_words.append(t)
Counter 패키지를 이용해서 리뷰 중에 가장 많이 언급된 단어만을 50개만 해서 시각화하도록 하겠다.
import sys
from collections import Counter
if sys.platform in ['win32','win64']:
font_name='malgun gothic'
rc('font',family=font_name)
counts_selected=Counter(real_words)
counts_selected.most_common(50)
counts_df=pd.DataFrame(counts_selected.most_common(50))
counts_df.columns=['keywords','counts']
plt.figure(figsize=(12,10))
sns.barplot(x='counts',y='keywords',data=counts_df)
역시 TV 제품 리뷰이다 보니 확실히 picture, sound, screen, remote, apps, hdmi, app, video 등 TV와 연관된 단어가 언급이 많은 점을 확인할 수 있다. 이런 그래프로는 쉽게 볼 수 없어서 워드클라우드로 한번 더 시각화했다.
from wordcloud import WordCloud
import platform
if platform.system()=='Windows':
font_path='c:/Windows/Fonts/malgun.ttf'
wordcloud=WordCloud(font_path=font_path,
background_color='white',
max_words=100,
relative_scaling=0.3,
width=800,
height=400).generate_from_frequencies(counts_selected)
plt.figure(figsize=(15,10))
plt.imshow(wordcloud)
plt.axis('off')
plt.savefig('test.png')
이번 포스팅에서는 우선 단어만 추출해서 시각화를 해봤다. 텍스트 관련 분석은 나도 이정도 밖에 못한다. 다음 포스징에는 공부를 좀 더 해보서 다양한 텍스트 관련 분석을 해보도록 하겠다.
728x90
반응형
'문송충의 코딩하기 > 파이썬 데이터 분석' 카테고리의 다른 글
[파이썬] - 유튜브 API를 활용해서 네고왕 조회, 좋아요, 댓글 수 가져오기 (1) | 2020.11.14 |
---|---|
[파이썬] - 서울시 열린데이터광장 오픈 API 활용해서 서울시 공영주차장 정보를 알아보자 (0) | 2020.11.08 |
[파이썬] - 아마존에서 삼성 QLED TV 고객 리뷰 크롤링해서 가져오기 (4) | 2020.11.03 |
[파이썬] - 서울시 공공시설 테니스장 데이터 가져오기 from 서울 공공데이터 API (1) | 2020.11.01 |
[파이썬] 서울시 공공데이터 API를 활용해 서울시 코로나19 확진자 데이터 분석하기 #1 (0) | 2020.10.27 |
댓글