Python数据可视化淘宝天猫店铺评论分析

Step 1. 导入模块

In [1]:

import numpy as np
import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
import jieba
import jieba.analyse
from stylecloud import gen_stylecloud

from IPython.display import Image # 用于在jupyter lab中显示本地图片

Step 2. 店铺评价数据分析及其可视化

2.1 店铺评价数据概览

In [3]:

df = pd.read_csv('/home/mw/input/luosifen4874/李子柒螺蛳粉评论.csv')
df.head(6)

Out[3]:

UserNickcomment_timecontentauctionSku
0太***42020-04-09 18:53:48整体评价:还不错呦,东西蛮好的,第一次买李子柒家东西呀,不错呀,棒棒哒 胀包问题:没有呀,包...口味:螺蛳粉3袋装
1秘***02020-04-10 13:33:19#柒家美拍达人#当吃到李子柒家第一口螺狮粉的时候,只想说,漫长的等待是值得的😁米粉爽滑Q弹,...口味:螺蛳粉3袋装
2m***32020-04-11 16:57:29整体评价:不错 胀包问题:无 包装品质:好 口感味道:辣椒半包就够了,挺香的 新鲜度:可以 ...口味:螺蛳粉3袋装
3爱***62020-04-10 17:52:28#柒家美拍达人# 等待了好久的美食终于到了,可以说期待了很久,拿到后激动了很久,想着一定给柒...口味:螺蛳粉3袋装
4t***22020-04-11 18:39:503 月11 号下单,4月11 号收到的,哈哈哈哈 不愧是我等了一个月的螺蛳粉,好吃到爆炸!!...口味:螺蛳粉3袋装
5t***92020-04-08 16:36:42据说,螺蛳粉的臭味,是因酸笋,而螺蛳粉的汤,由螺丝肉和骨头熬成,此举使汤清甜与鲜美,后加浓郁...口味:螺蛳粉3袋装

In [4]:

print("——" * 10)
print('数据集存在重复值个数:')
print(df.duplicated().sum())
print("——" * 10)
print('数据集缺失值情况:')
print(df.isna().sum())
print("——" * 10)
print('数据集各字段类型:')
print(df.dtypes)
print("——" * 10)
print('数据总体概览:')
print(df.info())
————————————————————
数据集存在重复值个数:
20
————————————————————
数据集缺失值情况:
UserNick        0
comment_time    0
content         0
auctionSku      0
dtype: int64
————————————————————
数据集各字段类型:
UserNick        object
comment_time    object
content         object
auctionSku      object
dtype: object
————————————————————
数据总体概览:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2000 entries, 0 to 1999
Data columns (total 4 columns):
UserNick        2000 non-null object
comment_time    2000 non-null object
content         2000 non-null object
auctionSku      2000 non-null object
dtypes: object(4)
memory usage: 62.6+ KB
None

In [5]:

df.drop_duplicates(inplace=True)

2.2 商品评价数量走势图

In [6]:

df['comment_time'] = pd.to_datetime(df['comment_time'])
df['comment_date'] = df['comment_time'].dt.date
comment_num = df['comment_date'].value_counts().sort_index()

Jan 52020Jan 19Feb 2Feb 16Mar 1Mar 15Mar 29Apr 12050100150200250300商品评价数量走势图日期热度

2.3 淘宝店铺评论数据处理

In [8]:

def judge_comment(df, result):

    # 创建一个空数据框
    judges = pd.DataFrame(np.zeros(13 * len(df)).reshape(len(df),13),
                      columns = ['品牌','物流正面','物流负面','包装正面','包装负面','原料正面',
                                 '原料负面','口感正面','口感负面','日期正面','日期负面',
                                 '性价比正面','性价比负面'])

    for i in range(len(result)):
        word = result[i]
        #李子柒的产品具有强IP属性,基本都是正面评价,这里不统计情绪,只统计提及次数
        if '李子柒' in word or '子柒' in word or '小柒' in word or '李子七' in word or '小七' in word:
                judges.iloc[i]['品牌'] = 1

        #先判断是不是物流相关的
        if '物流' in word or '快递' in word or '配送' in word or '取货' in word:
            #再判断是正面还是负面情感
            if '好' in word or '不错' in word or '棒' in word or '满意' in word or '迅速' in word:
                judges.iloc[i]['物流正面'] = 1
            elif '慢' in word or '龟速' in word or '暴力' in word or '差' in word:
                judges.iloc[i]['物流负面'] = 1

        #判断是否包装相关
        if '包装' in word or '盒子' in word or '袋子' in word or '外观' in word:
            if '高端' in word or '大气' in word or '还行' in word or '完整' in word or '好' in word or\
               '严实' in word or '紧' in word or '精致' in word:
                judges.iloc[i]['包装正面'] = 1
            elif  '破' in word or '破损' in word or '瘪' in word or '简陋' in word:
                judges.iloc[i]['包装负面'] = 1

        #产品
        #产品原料是牛肉为主,且评价大多会提到牛肉,因此我们把这个单独拎出来分析
        if '米粉' in word or '汤' in word or '配料' in word or '腐竹' in word or '花生' in word:
            if '劲道' in word or '多' in word or '足' in word or '香' in word or '才' in word or\
                '脆' in word or 'nice' in word:
                judges.iloc[i]['原料正面'] = 1
            elif '小' in word or '少' in word or '没' in word:
                judges.iloc[i]['原料负面'] = 1

        #口感的情绪
        if '口味' in word or '味道' in word or '口感' in word or '吃起来' in word:
            if '不错' in word or '浓鲜' in word or '十足' in word or '鲜' in word or\
                '可以' in word or '喜欢' in word or '符合' in word:
                judges.iloc[i]['口感正面'] = 1
            elif '不好' in word or '不行' in word or '不鲜' in word or\
                '太烂' in word:
                judges.iloc[i]['口感负面'] = 1

        #口感方面,有些是不需要出现前置词,消费者直接评价好吃难吃的,例如:
        if '难吃' in word or '不好吃' in word:
            judges.iloc[i]['口感负面'] = 1
        elif '好吃' in word or '香' in word:
            judges.iloc[i]['口感正面'] = 1

        #日期是不是新鲜
        if '日期' in word or '时间' in word or '保质期' in word:
            if '新鲜' in word:
                judges.iloc[i]['日期正面'] = 1
            elif '久' in word or '长' in word:
                judges.iloc[i]['日期负面'] = 1
        elif '过期' in word:
            judges.iloc[i]['日期负面'] = 1

        #性价比
        if '划算' in word or '便宜' in word or '赚了' in word or '囤货' in word or '超值' in word or \
            '太值' in word or '物美价廉' in word or '实惠' in word or '性价比高' in word or '不贵' in word: 
            judges.iloc[i]['性价比正面'] = 1
        elif  '贵' in word or '不值' in word or '亏了' in word or '不划算' in word or '不便宜' in word:
            judges.iloc[i]['性价比负面'] = 1

    final_result = pd.concat([df,judges],axis = 1)

    return final_result

# 得到数据框
judge = judge_comment(df, result=df.content)
judge.head(5) 

Out[8]:

UserNickcomment_timecontentauctionSkucomment_date品牌物流正面物流负面包装正面包装负面原料正面原料负面口感正面口感负面日期正面日期负面性价比正面性价比负面
0太***42020-04-09 18:53:48整体评价:还不错呦,东西蛮好的,第一次买李子柒家东西呀,不错呀,棒棒哒 胀包问题:没有呀,包...口味:螺蛳粉3袋装2020-04-091.00.00.01.00.00.00.01.00.01.00.00.00.0
1秘***02020-04-10 13:33:19#柒家美拍达人#当吃到李子柒家第一口螺狮粉的时候,只想说,漫长的等待是值得的😁米粉爽滑Q弹,...口味:螺蛳粉3袋装2020-04-101.00.00.00.00.01.00.01.00.00.00.00.00.0
2m***32020-04-11 16:57:29整体评价:不错 胀包问题:无 包装品质:好 口感味道:辣椒半包就够了,挺香的 新鲜度:可以 ...口味:螺蛳粉3袋装2020-04-110.00.00.01.00.01.00.01.01.00.00.00.00.0
3爱***62020-04-10 17:52:28#柒家美拍达人# 等待了好久的美食终于到了,可以说期待了很久,拿到后激动了很久,想着一定给柒...口味:螺蛳粉3袋装2020-04-101.00.00.00.00.01.00.01.00.00.00.00.00.0
4t***22020-04-11 18:39:503 月11 号下单,4月11 号收到的,哈哈哈哈 不愧是我等了一个月的螺蛳粉,好吃到爆炸!!...口味:螺蛳粉3袋装2020-04-110.00.00.01.00.00.00.01.00.01.00.00.00.0

In [9]:

rank = judge.iloc[:,5:].sum().reset_index().sort_values(0,ascending=False)
rank.columns = ['分类', '提及次数']
rank['占比'] = rank['提及次数'] / rank['提及次数'].sum()
rank['高级分类'] = rank['分类'].str[:-2]
rank

Out[9]:

分类提及次数占比高级分类
7口感正面1547.00.396565口感
3包装正面718.00.184055包装
5原料正面605.00.155088原料
0品牌474.00.121507
9日期正面186.00.047680日期
11性价比正面111.00.028454性价比
10日期负面74.00.018969日期
1物流正面62.00.015893物流
6原料负面57.00.014612原料
8口感负面34.00.008716口感
12性价比负面31.00.007947性价比
2物流负面1.00.000256物流
4包装负面1.00.000256包装

In [10]:

rank.loc[0, '高级分类'] = '品牌'
rank 

Out[10]:

分类提及次数占比高级分类
7口感正面1547.00.396565口感
3包装正面718.00.184055包装
5原料正面605.00.155088原料
0品牌474.00.121507品牌
9日期正面186.00.047680日期
11性价比正面111.00.028454性价比
10日期负面74.00.018969日期
1物流正面62.00.015893物流
6原料负面57.00.014612原料
8口感负面34.00.008716口感
12性价比负面31.00.007947性价比
2物流负面1.00.000256物流
4包装负面1.00.000256包装

In [11]:

rank_num = rank.groupby('高级分类')['提及次数'].sum().sort_values(ascending=False).reset_index()
rank_num

Out[11]:

高级分类提及次数
0口感1581.0
1包装719.0
2原料662.0
3品牌474.0
4日期260.0
5性价比142.0
6物流63.0

2.4 淘宝店铺消费者关注点占比分布

口感158140.5%包装71918.4%原料66217%品牌47412.2%日期2606.66%性价比1423.64%物流631.61%口感包装原料品牌日期性价比物流消费者关注点占比分布

2.7 店铺评价词云图

In [13]:

def get_cut_words(content_series):
    # 读入停用词表
    stop_words = [] 
    
    # 添加关键词
    my_words = [] 
    for i in my_words:
        jieba.add_word(i) 

    # 自定义停用词
    my_stop_words = ['40', 'hellip', '一袋', '一包', '一个月', 
                   '一点', '一个多月', '第一次', '哈哈哈', 
                   '螺狮粉', '螺蛳']
    stop_words.extend(my_stop_words)               

    # 分词
    word_num = jieba.lcut(content_series.str.cat(sep='。'), cut_all=False)

    # 条件筛选
    word_num_selected = [i for i in word_num if i not in stop_words and len(i)>=2]
    
    return word_num_selected

In [14]:

text = get_cut_words(content_series=df['content']) 
text[:10]
Building prefix dict from the default dictionary ...
Dumping model to file cache C:\Users\H1638\AppData\Local\Temp\jieba.cache
Loading model cost 2.150 seconds.
Prefix dict has been built successfully.

Out[14]:

['整体', '评价', '不错', '东西', '李子', '柒家', '东西', '不错呀', '棒棒', '问题']

Out[15]:

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

暴躁的秋秋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值