利用Python对美团某商家的评论销售进行数据分析

####导入相关库

from pyecharts import Bar,Pie
import pandas as pd
import numpy as np
import  matplotlib.pyplot as  plt
import time
'''
遇到不懂的问题?Python学习交流群:1136201545
满足你的需求,资料都已经上传群文件,可以自行下载!
'''

数据清洗与简单统计

  • 评论数据,其中包括一下几个字段
  • 是否匿名,均价,评价(以去掉,后续会做一些关于这些评论的更为深入的分析),评价时间,交易截止时间,订单号,套餐,上传的图片链接,质量好坏,阅读量,回复量,评分,点赞数等。
df=pd.read_excel("all_data_meituan.xlsx")
df.drop('comment',axis=1).head(2)

image.png

df['avgPrice'].value_counts()
# 同一家店的均价应该为同一个数值,所以这列数据没多大的意义
73    17400
Name: avgPrice, dtype: int64
df['anonymous'].value_counts()
# 匿名评价与实名评价的比例大致在5:1左右
False    14402
True      2998
Name: anonymous, dtype: int64

####时间格式的转化

def convertTime(x):
    y=time.localtime(x/1000)
    z=time.strftime("%Y-%m-%d %H:%M:%S",y)
    return z
df["commentTime"]=df["commentTime"].apply(convertTime)
df["commentTime"].head()
0    2018-05-09 22:21:48
1    2018-06-01 19:41:31
2    2018-04-04 11:52:23
3    2018-05-01 17:12:22
4    2018-05-17 16:48:04
Name: commentTime, dtype: object
# 在excel可以用筛选器直接看到这列中的数据含有缺失值,或者在拿到数据的时候,使用df.info() 查看每列的数据信息情况
df['dealEndtime'].isna().value_counts()
# 这列数据中含有177个缺失值,其余完整
False    17223
True       177
Name: dealEndtime, dtype: int64

image.png
####按月统计

df['commentTime']=pd.to_datetime(df['commentTime'])
df1 = df.set_index('commentTime')
df1.resample('D').size().sort_values(ascending=False).head(100)
df2=df1.resample('M').size().to_period()
df2=df2.reset_index()
# df2.columns
# from pyecharts import  Bar
bar =Bar("按月统计",width=1000,height=800)
bar.add("按月统计",df2['commentTime'],df2[0],is_label_show=True, is_datazoom_show=True,is_toolbox_show=True,is_more_utils=True)
bar

image.png
####按周统计

df['commentTime']=pd.to_datetime(df['commentTime'])
df['weekday'] = df['commentTime'].dt.weekday
df2= df.groupby(['weekday']).size()
#  周末吃外卖的还是教平时多了一些
from pyecharts import  Bar
bar =Bar("按周统计",width=750,height=400)
weekday=["一","二","三","四","五","六","日"]
bar.add("按周统计",['周{}'.format(i) for i in weekday],df2.values,is_label_show=True, is_datazoom_show=False,is_toolbox_show=True,is_more_utils=True,is_random=True)
bar

image.png
####按天统计
image.png
####按时统计

df['commentTime']=pd.to_datetime(df['commentTime'])
df['hour'] = df['commentTime'].dt.hour
df2= df.groupby(['hour']).size()
df2
from pyecharts import  Bar
bar =Bar("按时统计",width=1000,height=600)
bar.add("按时统计",['{} h'.format(i) for i in df2.index],df2.values,is_label_show=True, is_datazoom_show=True,is_toolbox_show=True,is_more_utils=True,is_random=True)
bar

image.png

  • 1
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值