新聞中心
一、數(shù)據(jù)來源

創(chuàng)新互聯(lián)是一家專業(yè)提供沂水企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、H5響應(yīng)式網(wǎng)站、小程序制作等業(yè)務(wù)。10年已為沂水眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)絡(luò)公司優(yōu)惠進(jìn)行中。
本節(jié)選用的是Python的第三方庫(kù)seaborn自帶的數(shù)據(jù)集,該小費(fèi)數(shù)據(jù)集為餐飲行業(yè)收集的數(shù)據(jù),其中total_bill為消費(fèi)總金額、tip為小費(fèi)金額、sex為顧客性別、smoker為顧客是否吸煙、day為消費(fèi)的星期、time為聚餐的時(shí)間段、size為聚餐人數(shù)。
- import numpy as np
- from pandas import Series,DataFrame
- import pandas as pd
- import seaborn as sns #導(dǎo)入seaborn庫(kù)
- tips=sns.load_dataset('tips') #seaborn庫(kù)自帶的數(shù)據(jù)集
- tips.head()
二、問題探索
- 小費(fèi)金額與消費(fèi)總金額是否存在相關(guān)性?
- 性別、是否吸煙、星期幾、聚餐人數(shù)和小費(fèi)金額是否有一定的關(guān)聯(lián)?
- 小費(fèi)金額占小費(fèi)總金額的百分比是否服從正態(tài)分布?
三、數(shù)據(jù)清洗
- tips.shape #數(shù)據(jù)集的維度
(244,7)
共有244條數(shù)據(jù),7列。
- tips.describe() #描述統(tǒng)計(jì)
描述統(tǒng)計(jì)結(jié)果如上所示。
- tips.info() #查看缺失值信息
此例無缺失值。
四、數(shù)據(jù)探索
- tips.plot(kind='scatter',x='total_bill',y='tip') #繪制散點(diǎn)圖
由圖可看出,小費(fèi)金額與消費(fèi)總金額存在正相關(guān)性。
- import numpy as np
- from pandas import Series,DataFrame
- import pandas as pd
- import seaborn as sns #導(dǎo)入seaborn庫(kù)
- tips=sns.load_dataset('tips')#seaborn庫(kù)自帶的數(shù)據(jù)集
- tips.head()
3.0896178343949052
- female_tip = tips[tips['sex'] == 'Female']['tip'].mean() #女性平均消費(fèi)金額female_tip
2.833448275862069
- s = Series([male_tip,female_tip],index=['male','female'])
- s
male 3.089618
female 2.833448
dtype: float64
- s.plot(kind='bar') #男女平均小費(fèi)柱狀圖
由圖可看出,女性小費(fèi)金額小于男性小費(fèi)金額。
- sun_tip = tips[tips['day'] == 'Sun']['tip'].mean()
- sat_tip = tips[tips['day'] == 'Sat']['tip'].mean()
- thur_tip = tips[tips['day'] == 'Thur']['tip'].mean()
- fri_tip = tips[tips['day'] == 'Fri']['tip'].mean()#各個(gè)日期的平均小費(fèi)值
- s = Series([thur_tip,fri_tip,sat_tip,sun_tip],index=['Thur','Fri','Sat','Sun'])
- s
- s.plot(kind='bar') #日期平均小費(fèi)柱狀圖
由圖可看出,周六、周日的小費(fèi)比周四、周五的小費(fèi)高。
- tips['percent_tip'] = tips['tip']/(tips['total_bill']+tips['tip'])
- tips.head(10) #小費(fèi)所占百分比
- tips['percent_tip'].hist(bins=50)#小費(fèi)百分比直方圖
由圖可看出,小費(fèi)金額占小費(fèi)總金額的百分比基本服從正態(tài)分布。
網(wǎng)站欄目:Python數(shù)據(jù)分析實(shí)戰(zhàn),小費(fèi)數(shù)據(jù)集應(yīng)用
本文來源:http://www.dlmjj.cn/article/djphieh.html


咨詢
建站咨詢
