import pandas as pd
import plotly
df = pd.read_excel('df_all_1130_4.xlsx')
df.head()
site | hotel | score | review | date | star | length | review_spell_check | helpful | attitude | 담당자 | 위치 | 시설 | 인테리어 | 청결 | 친절 | 방음 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 아고다 | 나인트리 프리미어 명동2 | 10.0 | 뷰 좋고 위치 좋고 깨끗하고 최고 입니다 | NaN | NaN | 22 | 뷰 좋고 위치 좋고 깨끗하고 최고입니다 | 1 | 2 | 주현 | 1 | 0 | 0 | 0 | 0 | 0 |
1 | 아고다 | 신라스테이 광화문 | 10.0 | 위치 시설 모두 좋아요 | NaN | NaN | 12 | 위치 시설 모두 좋아요 | 0 | 2 | 주현 | 1 | 1 | 0 | 0 | 0 | 0 |
2 | 아고다 | 신라스테이 광화문 | 2.0 | 침대에 빨래 먼지로 보이는 먼지가 이불침대 시트 모두에 한가득이었습니다 청소 상태... | NaN | NaN | 69 | 침대에 빨래 먼지로 보이는 먼지가 이불 침대 시트 모두에 한가득이었습니다 청소 상... | 1 | 0 | 주현 | 0 | 0 | 0 | 1 | 0 | 0 |
3 | 아고다 | 신라스테이 광화문 | 8.8 | 위치 시설 서비스 모두 다 만족합니다 | NaN | NaN | 20 | 위치 시설 서비스 모두 다 만족합니다 | 0 | 2 | 주현 | 1 | 1 | 0 | 0 | 0 | 0 |
4 | 아고다 | 신라스테이 광화문 | 8.0 | 주변에 식사장소도 많고 볼 곳도 많아서 좋습니다다만 주말에는 집회가 근처에서 많아 ... | NaN | NaN | 57 | 주변에 식사 장소도 많고 볼 곳도 많아서 좋습니다 다만 주말에는 집회가 근처에서 많... | 1 | 1 | 주현 | 1 | 0 | 0 | 0 | 0 | 1 |
import plotly.io as pio
import plotly.express as px
import plotly.graph_objects as go
import plotly.figure_factory as ff
from plotly.subplots import make_subplots
from plotly.validators.scatter.marker import SymbolValidator
import numpy as np
import pandas as pd
df['score_'] = df['score'].map(lambda x: round(x))
df['score_'].unique()
array([10, 2, 9, 8, 6, 4, 7, 3, 5], dtype=int64)
df['helpful'].value_counts()
0 1441 1 968 Name: helpful, dtype: int64
df['total'] = df[['위치', '시설', '인테리어',
'청결', '친절', '방음']].sum(axis=1)
df.sample(2)
site | hotel | score | review | date | star | length | review_spell_check | helpful | attitude | 담당자 | 위치 | 시설 | 인테리어 | 청결 | 친절 | 방음 | score_ | total | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2225 | 야놀자 | 신라스테이 광화문 | 2.0 | 정상적이 부분이 | 2020-11-06 00:00:00 | 1.0 | 8 | 정상적이 부분이 | 0 | 1 | 하나 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 |
123 | 아고다 | 나인트리 프리미어 명동2 | 10.0 | 두번째 숙박인데 역시나 위치가 좋음 게다가 가격도 매우 합리적임 숙소1층에 편의점 ... | NaN | NaN | 132 | 두 번째 숙박인데 역시나 위치가 좋음 게다가 가격도 매우 합리적임 숙소 1층에 편의... | 1 | 1 | 주현 | 1 | 1 | 0 | 0 | 0 | 0 | 10 | 2 |
pie = df.groupby(['helpful','total']).count().review
pie = pie.reset_index()
pie.head()
helpful | total | review | |
---|---|---|---|
0 | 0 | 0 | 855 |
1 | 0 | 1 | 390 |
2 | 0 | 2 | 158 |
3 | 0 | 3 | 35 |
4 | 0 | 4 | 2 |
#pie = df[df.helpful == 1].loc[:,['helpful','total']]
pie.columns = ['helpful','Category_count','review']
add = [(0,6,0),(1,6,0)]
add = pd.DataFrame(add, columns = pie.columns)
pie = pie.append(add, ignore_index = True)
pie = pie.sort_values(["helpful", "Category_count"])
#pie = pie[pie["Category_count"]!=0]
pie['Category_count'] = pie['Category_count'].map(lambda x : str(x))
pie
helpful | Category_count | review | |
---|---|---|---|
0 | 0 | 0 | 855 |
1 | 0 | 1 | 390 |
2 | 0 | 2 | 158 |
3 | 0 | 3 | 35 |
4 | 0 | 4 | 2 |
5 | 0 | 5 | 1 |
12 | 0 | 6 | 0 |
6 | 1 | 0 | 124 |
7 | 1 | 1 | 331 |
8 | 1 | 2 | 327 |
9 | 1 | 3 | 135 |
10 | 1 | 4 | 45 |
11 | 1 | 5 | 6 |
13 | 1 | 6 | 0 |
pie.groupby(["helpful"]).sum().review
helpful 0 1441 1 968 Name: review, dtype: int64
helpful = pie[pie.helpful == 1]
helpful["total"] = 968
#print(helpful)
helpful["rate"] = helpful["review"]/helpful["total"]
helpful
#helpful = helpful.iloc[:,1:]
helpful | Category_count | review | total | rate | |
---|---|---|---|---|---|
6 | 1 | 0 | 124 | 968 | 0.128099 |
7 | 1 | 1 | 331 | 968 | 0.341942 |
8 | 1 | 2 | 327 | 968 | 0.337810 |
9 | 1 | 3 | 135 | 968 | 0.139463 |
10 | 1 | 4 | 45 | 968 | 0.046488 |
11 | 1 | 5 | 6 | 968 | 0.006198 |
13 | 1 | 6 | 0 | 968 | 0.000000 |
#text position, textinfo
fig = px.pie(helpful, values = 'review', hover_data = ['Category_count'],
color_discrete_sequence = px.colors.sequential.dense, names = 'Category_count',labels = {'Category_count' : '포함된 카테고리 수'})
fig.update_traces(textposition = 'inside', textinfo = 'percent + label', textfont_size = 14,
marker = dict(line = dict(color = 'black', width = 1)))
fig.update_layout(title = "도움이 되는 리뷰",showlegend=True)
fig.show()
nonhelpful = pie[pie.helpful == 0]
#text position, textinfo
fig = px.pie(nonhelpful, values = 'review', hover_data = ['Category_count'],
color_discrete_sequence = px.colors.sequential.dense, names = 'Category_count',labels = {'Category_count' : '포함된 카테고리 수'})
fig.update_traces(textposition = 'inside', textinfo = 'percent + label', textfont_size = 14,
marker = dict(line = dict(color = 'black', width = 1)))
fig.update_layout(title = "도움이 되지 않는 리뷰",showlegend=True)
fig.show()