zoukankan      html  css  js  c++  java
  • 【数据分析&数据挖掘】计算每日营业额&最火菜品统计

     1 import pandas as pd
     2 import numpy as np
     3 
     4 # 计算每日营业额 加载数据
     5 detail = pd.read_excel("./meal_order_detail.xlsx")
     6 print("detail: 
    ", detail)
     7 print("detail的列名称: 
    ", detail.columns)
     8 
     9 # 1、计算出每个产品的营业额
    10 detail.loc[:, "pay"] = detail.loc[:, "counts"] * detail.loc[:, "amounts"]
    11 print(detail)
    12 
    13 # 2、构建日数据
    14 # 先将时间数据转化为pandas默认支持的时间序列数据
    15 detail.loc[:, "place_order_time"] = pd.to_datetime(detail.loc[:, "place_order_time"])
    16 
    17 # 通过列表推导式来获取日属性
    18 detail.loc[:, "day"] = [i.day for i in detail.loc[:, "place_order_time"]]
    19 
    20 print(detail)
    21 
    22 # 3、计算营业额——按照日进行分组,统计pay的sum
    23 res = detail.groupby(by="day")["pay"].sum()
    24 # res = detail.groupby(by="day")["pay"]  # 一个对象
    25 
    26 print("res: 
    ", res)
     1 # 求这家店最火的菜品,以及售卖份数
     2 import pandas as pd
     3 
     4 # 加载数据
     5 detail = pd.read_excel("./meal_order_detail.xlsx")
     6 print("detail: 
    ", detail)
     7 print("detail的列名称: 
    ", detail.columns)
     8 
     9 # 先将dishes_name转化为category类型
    10 detail.loc[:, "dishes_name"] = detail.loc[:, "dishes_name"].astype("category")
    11 
    12 # 统计describe分析
    13 print("对于菜品最火及售卖份数的统计分析: 
    ", detail.loc[:, "dishes_name"].describe())
    14 
    15 # 白饭/大碗不算菜品
    16 # 删除白饭的行
    17 bool_index = detail.loc[:, "dishes_name"] == "白饭/大碗"
    18 print("bool_index")
    19 
    20 # 确定哪些行是白饭大碗
    21 drop_index_list = detail.loc[bool_index, :].index
    22 
    23 # 删除
    24 detail.drop(labels=drop_index_list, axis=0, inplace=True)
    25 
    26 # 保留法
    27 bool_id = detail.loc[:, "dishes_name"] != "白饭/大碗"
    28 
    29 # 保留True的行
    30 detail = detail.loc[bool_id, :]
    31 
    32 # 再去统计菜品的deccribe
    33 
    34 # 先将dishes_name转化为category类型
    35 detail.loc[:, "dishes_name"] = detail.loc[:, "dishes_name"].astype("category")
    36 
    37 # 统计describe分析
    38 print("对于菜品最火以及售卖份数的统计分析: 
    ", detail)
  • 相关阅读:
    JavaScript根据CSS的Media Queries来判断浏览设备的方法
    JavaScript API 设计原则
    高性能 CSS3 动画
    CSS代码实例:用CSS代码写出的各种形状图形
    frontpage 2010.2003绿色版
    Web前端年后跳槽必看的各种面试题
    [ksm][数学] Jzoj P5810 简单的玄学
    [分治] Jzoj P5807 简单的区间
    [dfs][bfs] Jzoj P5806 简单的操作
    [dp] Jzoj P5804 简单的序列
  • 原文地址:https://www.cnblogs.com/Tree0108/p/12116079.html
Copyright © 2011-2022 走看看