淘宝天猫玩具销售数据可视化(下)

简介: 淘宝天猫玩具销售数据可视化(下)

淘宝天猫玩具销售数据可视化(上)https://developer.aliyun.com/article/1507875


附录

1. 导入模块

import numpy as np
import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
import jieba
from stylecloud import gen_stylecloud
from IPython.display import Image

2. 乐高淘宝数据分析及其可视化
2.1 乐高淘宝数据概览

df_tb =pd.read_csv('乐高淘宝数据.csv')
df_tb.head()

print("——" * 10)
print('数据集存在重复值个数:')
print(df_tb.duplicated().sum())
print("——" * 10)
print('数据集缺失值情况:')
print(df_tb.isna().sum())
print("——" * 10)
print('数据集各字段类型:')
print(df_tb.dtypes)
print("——" * 10)
print('数据总体概览:')
print(df_tb.info())

2.2 乐高淘宝数据处理

# 去除重复值
df_tb.drop_duplicates(inplace=True) 
# 删除购买人数为空的记录 
df_tb = df_tb[df_tb['purchase_num'].str.contains('人付款')] 

# 重置索引 
df_tb = df_tb.reset_index(drop=True)
df_tb.info()

# purchase_num处理 
df_tb['purchase_num'] = df_tb['purchase_num'].str.extract('(\d+)').astype('int')

# 计算销售额 
df_tb['sales_volume'] = df_tb['price'] * df_tb['purchase_num']

#location
df_tb['province'] = df_tb['location'].str.split(' ').str[0]
df_tb.head(5) 

2.3 乐高销量排名淘宝店铺Top50

shop_top100 = df_tb.groupby('shop_name')['purchase_num'].sum().sort_values(ascending=False).reset_index()[:50]

px.bar(shop_top100,  # 上面指定的数据
       title="乐高销量排名淘宝店铺Top50",
       template="plotly_white",  # 分别主题设置为:plotly、plotly_dark
       x="shop_name",  # 横坐标
       y="purchase_num",  # 纵坐标
       color="purchase_num",
      labels={"shop_name": "店铺名称", "purchase_num": "销量"})  # 颜色取值

2.4 乐高产地数量排名top50

province_top50 = df_tb.province.value_counts().reset_index()[:50]


px.bar(province_top50,  # 上面指定的数据
       title="乐高产地数量排名top50",
       template="plotly_white",  # 分别主题设置为:plotly、plotly_dark
       x="index",  # 横坐标
       y="province",  # 纵坐标
       color="province",
      labels={"index": "地区", "province": "店铺统计数"})  # 颜色取值

2.5 天猫乐高价格分布

cut_bins = [0,50,100,200,300,500,1000,8888]  
cut_labels = ['0~50元', '50~100元', '100~200元', '200~300元', '300~500元', '500~1000元', '1000元以上']

price_cut = pd.cut(df_tb['price'],bins=cut_bins,labels=cut_labels)
price_num = price_cut.value_counts().reset_index()


fig = px.pie(price_num,
             names="index",
             values="price",
             color="price",
             hole=0.3,   # 设置中间空心圆的比例:0-1之间
             labels={"index": "价格区间", "price": "价格数量"}
            )

fig.update_layout(
    title={   # 设置整个标题的名称和位置
        "text":"天猫乐高价格分布",
        "y":0.96,  # y轴数值
        "x":0.5,  # x轴数值
        "xanchor":"center",  # x、y轴相对位置
        "yanchor":"top"  
    }
)
fig.update_traces(
 textposition='inside',
    textinfo='percent+value+label',
    textfont_size=20,
    marker=dict(
                line=dict(color='#000000',
                          width=1)))
fig.show()

2.6 不同价格区间的销售额整体表现分布

df_tb['price_cut'] = price_cut 

cut_purchase = df_tb.groupby('price_cut')['sales_volume'].sum().reset_index()


fig = px.pie(cut_purchase,
             names="price_cut",
             values="sales_volume",
             color="sales_volume",
             hole=0.3,   # 设置中间空心圆的比例:0-1之间
             labels={"price_cut": "价格区间", "sales_volume": "销售额"}
            )

fig.update_layout(
    title={   # 设置整个标题的名称和位置
        "text":"不同价格区间的销售额整体表现分布",
        "y":0.96,  # y轴数值
        "x":0.5,  # x轴数值
        "xanchor":"center",  # x、y轴相对位置
        "yanchor":"top"  
    }
)
fig.update_traces(
 textposition='inside',
    textinfo='percent+value+label',
    textfont_size=20,
    marker=dict(
                line=dict(color='#000000',
                          width=1)))
fig.show()

2.7 淘宝乐高标题词云图

def get_cut_words(content_series):
    # 读入停用词表
    stop_words = [] 
    
    # 添加关键词
    my_words = ['乐高', '悟空小侠', '大颗粒', '小颗粒'] 
    for i in my_words:
        jieba.add_word(i) 

    # 自定义停用词
    my_stop_words = []
    stop_words.extend(my_stop_words)               

    # 分词
    word_num = jieba.lcut(content_series.str.cat(sep='。'), cut_all=False)

    # 条件筛选
    word_num_selected = [i for i in word_num if i not in stop_words and len(i)>=2]
    
    return word_num_selected
text = get_cut_words(content_series=df_tb['goods_name']) 
text[:10]
# 绘制词云图
gen_stylecloud(
    text=' '.join(text),
    collocations=False,
    font_path=r'‪C:\Windows\Fonts\msyh.ttc',
    icon_name='fas fa-plane',
    size = 768,
    output_name='淘宝乐高标题词云图.png'
)
Image(filename='淘宝乐高标题词云图.png')

3. 乐高天猫旗舰店数据分析及其可视化
3.1 乐高天猫旗舰店数据概览

df_tm = pd.read_csv('天猫乐高旗舰店数据.csv')
df_tm.head()

3.2 乐高天猫旗舰店数据处理

df_tm.drop_duplicates(inplace=True)

# 价格处理
def transform_price(x):
    if '-' in x:
        return (float(x.split('-')[1]) - float(x.split('-')[0]))/2
    else:
        return x 

# 价格转换
df_tm['price'] = df_tm.price.apply(lambda x:transform_price(x)).astype('float')

# 使用平均值填充缺失值
df_tm['sales_num'] = df_tm.sales_num.replace('无',200)

#转换类型
df_tm['sales_num'] = df_tm.sales_num.astype('int')


df_tm['title'] = df_tm.title.str.replace('乐高旗舰店|官网|2020年', '')

#销售额
df_tm['sales_volume'] = df_tm['sales_num'] * df_tm['price']


rank_top50 = df_tm.groupby('title')['sales_num'].sum().sort_values(ascending=False).reset_index()[:50]

3.3 乐高旗舰店月销量商品top50

px.bar(rank_top50,  # 上面指定的数据
       title="乐高旗舰店月销量商品top50",
       template="plotly_white",  # 分别主题设置为:plotly、plotly_dark
       x="title",  # 横坐标
       y="sales_num",  # 纵坐标
       color="sales_num",
        height=1000,  # 自定义高度为600
      labels={"title": "商品", "sales_num": "销量"})  # 颜色取值

3.4 乐高旗舰店不同价格区间商品数量分布

cut_bins = [0,200,400,600,800,1000,2000,9469]
cut_labels = ['0~50元', '50~100元', '100~200元', '200~300元', '300~500元', '500~1000元', '1000元以上']

price_cut = pd.cut(df_tm['price'],bins=cut_bins,labels=cut_labels)
price_num = price_cut.value_counts().reset_index()




# 创建图表
fig = px.pie(
    price_num,
    names="index",
    values="price",
    color="price",
    hole=0.3,
    labels={"index": "价格区间", "price": "价格数量"},
    template="ggplot2"  # 使用ggplot2样式模板
)

# 修改布局
fig.update_layout(
    title={
        "text": "乐高旗舰店不同价格区间商品数量分布",
        "y": 0.96,
        "x": 0.5,
        "xanchor": "center",
        "yanchor": "top"
    },
    legend=dict(
        yanchor="top",
        y=0.9,
        xanchor="left",
        x=0.8,
        orientation="v"
    )
)


# 自定义颜色方案
colors = ['#FF9999', '#66B2FF', '#99FF99', '#FFCC99']
fig.update_traces(textposition='inside',
    textinfo='percent+value+label',
    textfont_size=20,marker=dict(colors=colors))

# 显示图表
fig.show()

3.5 乐高旗舰店不同价格区间的销售额整体表现

# 添加列
df_tm['price_cut'] = price_cut
cut_purchase = df_tm.groupby('price_cut')['sales_volume'].sum().reset_index()

# 创建图表
fig = px.pie(
    cut_purchase,
    names="price_cut",
    values="sales_volume",
    color="sales_volume",
    hole=0.3,
    labels={"price_cut": "价格区间", "sales_volume": "销售额"},
    template="ggplot2"  # 使用ggplot2样式模板
)

# 修改布局
fig.update_layout(
    title={
        "text": "乐高旗舰店不同价格区间的销售额整体表现",
        "y": 0.96,
        "x": 0.5,
        "xanchor": "center",
        "yanchor": "top"
    },
    legend=dict(
        yanchor="top",
        y=0.9,
        xanchor="left",
        x=0.8,
        orientation="v"
    )
)


# 自定义颜色方案
colors = ['#FF9999', '#66B2FF', '#99FF99', '#FFCC99']
fig.update_traces(textposition='inside',
    textinfo='percent+value+label',
    textfont_size=20,marker=dict(colors=colors))

# 显示图表
fig.show()

3.6 乐高旗舰店商品标题词云图

text = get_cut_words(content_series=df_tm['title'])
text[:6]

gen_stylecloud(
    text=' '.join(text),
    collocations=False,
    font_path=r'‪C:\Windows\Fonts\msyh.ttc',
    icon_name='fas fa-gamepad',
    size=768,
    output_name='乐高旗舰店商品标题词云图.png'
)
Image(filename='乐高旗舰店商品标题词云图.png')


目录
相关文章
|
数据采集 数据挖掘 API
主流电商平台数据采集API接口|【Python爬虫+数据分析】采集电商平台数据信息采集
随着电商平台的兴起,越来越多的人开始在网上购物。而对于电商平台来说,商品信息、价格、评论等数据是非常重要的。因此,抓取电商平台的商品信息、价格、评论等数据成为了一项非常有价值的工作。本文将介绍如何使用Python编写爬虫程序,抓取电商平台的商品信息、价格、评论等数据。 当然,如果是电商企业,跨境电商企业,ERP系统搭建,我们经常需要采集的平台多,数据量大,要求数据稳定供应,有并发需求,那就需要通过接入电商API数据采集接口,封装好的数据采集接口更方便稳定高效数据采集。
|
存储
[simulink] --- simulink模块(三)
[simulink] --- simulink模块(三)
1556 0
|
7月前
|
数据采集 JSON API
深入解析:使用 Python 爬虫获取淘宝店铺所有商品接口
本文介绍如何使用Python结合淘宝开放平台API获取指定店铺所有商品数据。首先需注册淘宝开放平台账号、创建应用并获取API密钥,申请接口权限。接着,通过构建请求、生成签名、调用接口(如`taobao.items.search`和`taobao.item.get`)及处理响应,实现数据抓取。代码示例展示了分页处理和错误处理方法,并强调了调用频率限制、数据安全等注意事项。此技能对开发者和数据分析师极具价值。
|
数据可视化 数据挖掘 数据处理
淘宝天猫玩具销售数据可视化(上)
淘宝天猫玩具销售数据可视化
440 1
|
12月前
|
存储 NoSQL 物联网
这些案例展示了MongoDB在不同行业中的广泛应用
这些案例展示了MongoDB在不同行业中的广泛应用
586 4
|
Linux 网络安全 Apache
源码安装----httpd
源码安装----httpd
540 1
|
存储 数据处理 索引
数据类型转换:int()、str()、float()
在Python中,数据类型转换是一项基础且重要的操作
|
Windows
Anaconda——安装及基本使用
Anaconda——安装及基本使用
446 0
|
监控 数据挖掘 Linux
Linux命令jobs:后台任务管理利器
`jobs`是Linux终端的利器,用于管理和查看后台任务。它显示当前会话中的作业状态,如运行、停止,可通过`Ctrl+Z`暂停任务,`bg`放后台,`fg`回前台。参数`-l`显示PID,`-n`显示最近状态变化的作业。`jobs`帮助高效监控和管理长时间运行的命令,如在数据分析时。记得使用正确任务编号,谨慎使用`kill`,并定期检查任务状态。
|
JSON 数据管理 测试技术
自动化测试工具Selenium Grid的深度应用分析深入理解操作系统的内存管理
【5月更文挑战第28天】随着互联网技术的飞速发展,软件测试工作日益复杂化,传统的手工测试已无法满足快速迭代的需求。自动化测试工具Selenium Grid因其分布式执行特性而受到广泛关注。本文旨在深入剖析Selenium Grid的工作原理、配置方法及其在复杂测试场景中的应用优势,为测试工程师提供高效测试解决方案的参考。