最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

餐廳訂單數(shù)據(jù)分析(源碼自用)

2023-03-17 19:44 作者:無真凡塵  | 我要投稿

import pandas as pd

import numpy as np

from matplotlib import pyplot as plt

plt.rcParams['font.sans-serif'] = 'SimHei'? ?# 設(shè)置中文



'''

分析可得信息

1.訂單表的長度,shape,columns

2.統(tǒng)計菜品的平均價格(amounts)

3.什么菜最受歡迎

4.哪個訂單ID點的菜最多

......

'''


# 1 加載數(shù)據(jù)

data1 = pd.read_excel("meal_order_detail.xls",sheet_name="meal_order_detail1")

data2 = pd.read_excel("meal_order_detail.xls",sheet_name="meal_order_detail2")

data3 = pd.read_excel("meal_order_detail.xls",sheet_name="meal_order_detail3")


# 2 數(shù)據(jù)預處理(合并數(shù)據(jù),NA處理),分析數(shù)據(jù)

data = pd.concat([data1,data2,data3],axis=0)? # 上下拼接

data.dropna(axis=1,inplace=True)? # 按列刪除na列,并且修改源數(shù)據(jù)


# 統(tǒng)計8月賣出菜品的平均價格

average1 = round(data['amounts'].mean(),2)? ?# 方法一:pandas自帶函數(shù)

average2 = round(np.mean(data['amounts']),2)? ?# 方法二:numpy函數(shù)處理


# 頻數(shù)統(tǒng)計,什么菜最受歡迎 (對菜名進行頻數(shù)統(tǒng)計,取最大前10名)

dishes_count = data['dishes_name'].value_counts()[:10]

'''

# 3 數(shù)據(jù)可視化matplotlib

dishes_count.plot(kind='line',color='r')? #頂部顯示折線

dishes_count.plot(kind='bar',fontsize=16)

for x,y in enumerate(dishes_count):? ? #頂部顯示數(shù)字

? ? plt.text(x,y+2,y,ha='center',fontsize=12)

plt.show()


# 訂單點菜的種類最多

data_group = data['order_id'].value_counts()[:10]

data_group.plot(kind='bar',fontsize=16,color=['r','m','b','y','g'])

plt.title('訂單點菜的種類Top10')

plt.xlabel('訂單ID',fontsize=16)

plt.ylabel('點菜種類',fontsize=16)

plt.show()

# 8月份餐廳訂單點菜種類前10名,平均點菜25個菜品


# 訂單ID點菜數(shù)量Top10(分組order_id,counts求和,排序,前10)

data['total_amounts'] = data['counts']*data['amounts']? # 統(tǒng)計單道菜消費總額

dataGroup = data[['order_id','counts','amounts','total_amounts']].groupby(by='order_id')

Group_sum = dataGroup.sum()? ? # 分組求和

sort_counts = Group_sum.sort_values(by='counts',ascending=False)

sort_counts['counts'][:10].plot(kind='bar',fontsize=16)

plt.xlabel('訂單ID')

plt.ylabel('點菜數(shù)量')

plt.title('訂單ID點菜數(shù)量Top10')

# plt.show()

# 8月份訂單點菜數(shù)量前10名


# 哪個訂單ID吃的錢做多

sort_total_amounts = Group_sum.sort_values(by='total_amounts',ascending=False)

sort_total_amounts['total_amounts'][:10].plot(kind='bar')

plt.xlabel('訂單ID')

plt.ylabel('消費金額')

plt.title('消費金額前10名')

# plt.show()


# 哪個訂單ID平均消費最貴

Group_sum['average'] = Group_sum['total_amounts']/Group_sum['counts']

sort_average = Group_sum.sort_values(by='average',ascending=False)

sort_average['average'][:10].plot(kind='bar')

plt.xlabel('訂單ID')

plt.ylabel('消費單價')

plt.title('消費單價前10名')

# plt.show()


# 一天當中什么時間段,點菜量比較集中(hour)

data['hourcount'] = 1? # 新列:用作計數(shù)器

data['time'] = pd.to_datetime(data['place_order_time'])? # 將時間轉(zhuǎn)換成日期類型存儲

# data['hour'] = data['time'].map(lambda x:x.hour)

# gp_by_hour = data.groupby(by='hour').count()['hourcount']

# gp_by_hour.plot(kind='bar')

# plt.xlabel('小時')

# plt.ylabel('點菜數(shù)量')

# plt.title('點菜數(shù)與小時的關(guān)系圖')

# plt.show()


# 8月份哪一天訂餐數(shù)量最多

data['daycount'] = 1

data['day'] = data['time'].map(lambda x:x.day)? # 解析出天

gp_by_day = data.groupby(by='day').count()['daycount']

# rank = gp_by_day.sort_values(ascending=False)[:5]

# rank.plot(kind='bar')

gp_by_day.plot(kind='bar')

plt.xlabel('8月份日期')

plt.ylabel('點菜數(shù)量')

plt.title('點菜數(shù)量與日期的關(guān)系圖')

plt.show()

# 拓展:排序,取點菜量最大的前5天(Done)


# 查看星期幾人數(shù)最多,訂餐數(shù)最多,映射數(shù)據(jù)到星期

data['weekcount'] = 1

data['weekday'] = data['time'].map(lambda x:x.weekday())

gp_by_weekday = data.groupby(by='weekday').count()['weekcount']

gp_by_weekday.plot(kind='bar')

plt.xlabel('星期')

plt.ylabel('點菜數(shù)量')

plt.title('點菜數(shù)量與星期的關(guān)系圖')

plt.show()

'''


'''

不同維度進行數(shù)據(jù)分析:

針對訂單order_id:

? ? ? ? 什么菜最受歡迎

? ? ? ? 點菜的種類

? ? ? ? 點菜的數(shù)量

? ? ? ? 消費金額最大

? ? ? ? 平均消費

針對時間日期進行分析:

? ? ? ? 點菜量比較集中的時間

? ? ? ? 哪一天訂餐數(shù)量最大

? ? ? ? 星期幾就餐人數(shù)最多

技術(shù)點:

? ? ? ? 拼接數(shù)據(jù):pd.concat([列1,...])

? ? ? ? 分組統(tǒng)計(求和)

? ? ? ? 排序,切片Top10

? ? ? ? 繪制柱狀圖走勢和高度

? ? ? ??

'''


餐廳訂單數(shù)據(jù)分析(源碼自用)的評論 (共 條)

分享到微博請遵守國家法律
雅江县| 贵溪市| 孟村| 聊城市| 益阳市| 吉首市| 雷州市| 武定县| 米林县| 怀化市| 永城市| 静海县| 张家口市| 门源| 天祝| 那坡县| 宁阳县| 梅州市| 石棉县| 博乐市| 兴海县| 从江县| 信宜市| 广平县| 黑山县| 天津市| 金昌市| 台山市| 庆城县| 铜梁县| 长沙市| 泸溪县| 饶河县| 房产| 宜川县| 永州市| 平乡县| 乌拉特后旗| 轮台县| 九龙县| 庆阳市|