【60 Pandas+Pyecharts | 箱包订单数据分析可视化】

发布于:2025-06-15 ⋅ 阅读:(15) ⋅ 点赞:(0)


大家好,我是 👉 【Python当打之年(点击跳转)】

本期我们利用Python分析「箱包订单数据集」,看看:各月订单量和订单金额占比、各季度订单量占比、每天订单金额分布、每小时订单金额分布、全年订单金额日历、各分类订单量等等,希望对大家有所帮助,如有疑问或者需要改进的地方可以联系小编。

涉及到的库:

  • Pandas— 数据处理
  • Pyecharts— 数据可视化

🏳️‍🌈 1. 导入模块

import pandas as pd
from pyecharts.charts import *
from pyecharts import options as opts
import warnings
warnings.filterwarnings('ignore')

🏳️‍🌈 2. Pandas数据处理

2.1 读取数据

df = pd.read_excel('./箱包订单数据.xlsx')

在这里插入图片描述

2.2 数据信息

df.info()

在这里插入图片描述

2.3 去除订单金额为空的数据

df = df.dropna(subset=['订单金额'])

2.4 提取年月日

df['订单日期'] = pd.to_datetime(df['订单日期'])
df['年'] = df['订单日期'].dt.year
df['月'] = df['订单日期'].dt.month
df['日'] = df['订单日期'].dt.day

2.5 提取季度和星期

df['季度'] = df['订单日期'].dt.quarter
df['周'] = df['订单日期'].dt.day_name()

在这里插入图片描述

🏳️‍🌈 3. Pyecharts数据可视化

3.1 每月订单量和订单金额分布

def get_c1():
    bar1 = (
        Bar()
        .add_xaxis(x_data)
        .add_yaxis('订单量', y_data)
        .extend_axis(
            yaxis=opts.AxisOpts(
                type_='value',
                axislabel_opts=opts.LabelOpts(formatter='{value}万元'), 
            )
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(title='1-每月订单量和订单金额分布',subtitle=subtitle,pos_top='2%',pos_left='center'),
        )
    )

    line1 = (
        Line()
            .add_xaxis(x_data)
            .add_yaxis(
                series_name='订单金额',
                yaxis_index=1,
                y_axis=y_data1,
            )
    )
    bar1.overlap(line1)

在这里插入图片描述

  • 11月的订单量和订单金额最高,其次是6月和3月。

3.2 各季度订单量占比

def get_c2():
    pie1 = (
        Pie()
        .add('',
             data,
             radius=['40%', '70%'],
             center=['50%', '55%'],
            )
        .set_global_opts(
            title_opts=opts.TitleOpts(title='2-各季度订单量占比',
                                      subtitle=subtitle,
                                      pos_top='2%',
                                      pos_left='center',
                                     ),
            visualmap_opts=opts.VisualMapOpts(is_show=False),
            legend_opts=opts.LegendOpts(is_show=False)
        )
    )

在这里插入图片描述

  • 第2季度和第4季度的订单占比都在30%左右,相较于第1季度和第3几度要高出10个百分点。

3.3 每天订单量和订单金额分布

在这里插入图片描述

  • 月初的订单量和订单金额相较于月末来的更多。

3.4 每小时订单金额分布

def get_c4():
    line2 = (
        Line()
        .add_xaxis(x_data)
        .add_yaxis('', y_data,areastyle_opts=opts.AreaStyleOpts(opacity=0.8))
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title='4-每小时订单金额分布',
                subtitle=subtitle,
                pos_top='2%',
                pos_left='center',
            ),
            visualmap_opts=opts.VisualMapOpts(
                is_show=False,
            ),
        )
    )

在这里插入图片描述

  • 晚间时段的订单量达到高峰,集中在20:00-24:00这个时间区间内,上午时间09:00-11:00段内也出现一波小高峰

3.5 一星期各天订单金额分布

在这里插入图片描述

  • 周一和周三两天的订单金额最高,最低的是周六。

3.6 全年订单金额日历热图

在这里插入图片描述

3.7 等级I分类订单量

def get_c7():
    bar2 = (
        Bar()
        .add_xaxis(x_data)
        .add_yaxis('', y_data,label_opts=opts.LabelOpts(position='right'))
        .reversal_axis()
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title='7-等级I分类订单量',
                subtitle=subtitle,
                pos_top='2%',
                pos_left='center',
            ),
            visualmap_opts=opts.VisualMapOpts(
                is_show=False,
            ),
        )

在这里插入图片描述

  • 手袋、银包类箱包订单量排在前两位,物料、服装、饰品等分类的箱包订单量排在第3-5位。

3.8 等级II分类订单量象形图

在这里插入图片描述

  • 长款票夹、腰包的订单量要远高于其他II级分类箱包。

3.9 产品名称订单量词云

def get_c9():
    wordcloud1 = (
        WordCloud()
        .add('',words,word_size_range=[30,70])
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title='9-产品名称订单量词云',
                pos_top='2%',
                pos_left="center",
            ),
            visualmap_opts=opts.VisualMapOpts(
                is_show=False,
            )
        )
    )

在这里插入图片描述

🏳️‍🌈 4. 可视化项目源码+数据

点击跳转:【全部可视化项目源码+数据】


以上就是本期为大家整理的全部内容了,赶快练习起来吧,原创不易,喜欢的朋友可以点赞、收藏也可以分享注明出处)让更多人知道。