探索性分析
数据是3W大众点评八大热门糖水店的评论,包含字段:顾客id、评论时间、评分、评论内容、口味、环境、服务、店铺ID
#引入库
import pandas as pd
from matplotlib import pyplot as plt
import pymysql
import seaborn as sns
from wordcloud import WordCloud, STOPWORDS
%matplotlib inline
数据库读入数据
我们使用pymysql库连接mysql数据库,pd.read_sql函数直接通过连接读取数据库数据
#连接数据库,读入数据
db = pymysql.connect("localhost",'root','root','dianping') #服务器:localhost,用户名:root,密码:(空),数据库:TESTDB
sql = "select * from dzdp;"
data = pd.read_sql(sql,db)
db.close()
数据概要
查看数据大小以及基础信息
data.shape
(32483, 14)
data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 32483 entries, 0 to 32482
Data columns (total 14 columns):
cus_id 32483 non-null object
comment_time 32483 non-null object
comment_star 32483 non-null object
cus_comment 32474 non-null object
kouwei 32483 non-null object
huanjing 32483 non-null object
fuwu 32483 non-null object
shopID 32483 non-null object
stars 26847 non-null object
year 32483 non-null object
month 32483 non-null object
weekday 32483 non-null object
hour 32483 non-null object
comment_len 32483 non-null object
dtypes: object(14)
memory usage: 3.5+ MB
data.head()
cus_id | comment_time | comment_star | cus_comment | kouwei | huanjing | fuwu | shopID | stars | year | month | weekday | hour | comment_len | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 迷糊泰迪 | 2018-09-20 06:48:00 | sml-str40 | 南信 算是 广州 著名 甜品店 吧 好几个 时间段 路过 都 是 座无虚席 看着 餐单 上 ... | 非常好 | 好 | 好 | 518986 | 4.0 | 2018 | 9 | 3 | 6 | 184 |
1 | 稱霸幼稚園 | 2018-09-22 21:49:00 | sml-str40 | 中午 吃 完 了 所谓 的 早茶 回去 放下 行李 休息 了 会 就 来 吃 下午茶 了 服... | 很好 | 很好 | 很好 | 518986 | 4.0 | 2018 | 9 | 5 | 21 | 266 |
2 | 爱吃的美美侠 | 2018-09-22 22:16:00 | sml-str40 | 冲刺 王者 战队 吃遍 蓉城 战队 有 特权 五月份 和 好 朋友 毕业 旅行 来 了 广州... | 很好 | 很好 | 很好 | 518986 | 4.0 | 2018 | 9 | 5 | 22 | 341 |
3 | 姜姜会吃胖 | 2018-09-19 06:36:00 | sml-str40 | 都 说来 广州 吃 糖水 就要 来南信 招牌 姜撞奶 红豆 双皮奶 牛 三星 云吞面 一楼 ... | 非常好 | 很好 | 很好 | 518986 | 4.0 | 2018 | 9 | 2 | 6 | 197 |
4 | forevercage | 2018-08-24 17:58:00 | sml-str50 | 一直 很 期待 也 最 爱 吃 甜品 广州 的 甜品 很 丰富 很 多样 来 之前 就 一直... | 非常好 | 很好 | 很好 | 518986 | 5.0 | 2018 | 8 | 4 |