电子产品销售数据分析及RFM用户价值分析

目录

项目背景

实战案例

1 读取数据

1.1  字段解析

 1.2  数据基础信息查看

 1.3  数据存储最小格式

2  数据清洗

2.1  查看缺失值比例

2.2  查看重复值比例

合成新列:buy_count

合成新列:购买总金额(GMV)

2.3  检测异常值

2.3.1  转化id数据格式

2.3.2  检查price,age是否有异常值

2.3.3  其他字段是否有异常值

3  数据探索性分析(EDA)

3.1  总览

3.1.1  总成交金额GMV

3.1.2  月成交金额GMV

月度GMV可视化 

 3.1.3  客单价

3.2  用户分析

3.2.1  用户区域特征

3.2.2  用户性别特征

3.2.3  用户年龄特征

3.2.4  用户消费特征

4  RFM模型

4.1  M:消费金额

4.2  F:消费频率

4.3  R:最近一次消费

4.4  RFM打分体系

4.5  用户打标

4.6  RFM用户价值模型可视化

案例全代码

参考文章


项目背景

RFM是一种经典的业务分析模型。通过对客户购买行为的3个维度R(最近购买),F(购买频次),M(购买)金额进行打分,进而对客户价值类型进行分类。经典的RFM模型将客户分为8类。不同类型的客户对企业的贡献是截然不同的,针对不同价值的客户企业需要制定不同的营销对策。

  • 近度(Recency,最近一次消费到当前的时间间隔)
  • 频度(Frequency,最近一段时间内的消费次数)
  • 额度(Monetory,最近一段时间内的消费金额总额/均额)

实战案例

电子产品销售数据分析及RFM用户价值分析

内容是分析消费类电子产品(主要指不同品牌手机及配件)在某电商平台的销售数据。

全代码notebook文件及原始数据文件附于文末。

1 读取数据

1.1  字段解析

  • Unnamed: 行号
  • event_time:下单时间
  • order_id:订单编号
  • product_id:产品标号
  • category_id :类别编号
  • category_code :类别
  • brand :品牌
  • price :价格
  • user_id :用户编号
  • age :年龄
  • sex :性别
  • local:省份

 1.2  数据基础信息查看

 

 1.3  数据存储最小格式

看上一步最后,数据大小50+MB,读取还是需要5-10秒的,这里介绍一段缩减数据类存储空间的代码。

# reduce memory
def reduce_mem_usage(df, verbose=True):
    start_mem = df.memory_usage().sum() / 1024**2
    numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']

    for col in df.columns:
        col_type = df[col].dtypes
        if col_type in numerics:
            c_min = df[col].min()
            c_max = df[col].max()
            if str(col_type)[:3] == 'int':
                if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:
                    df[col] = df[col].astype(np.int8)
                elif c_min > np.iinfo(np.int16).min and c_max < np.iinfo(np.int16).max:
                    df[col] = df[col].astype(np.int16)
                elif c_min > np.iinfo(np.int32).min and c_max < np.iinfo(np.int32).max:
                    df[col] = df[col].astype(np.int32)
                elif c_min > np.iinfo(np.int64).min and c_max < np.iinfo(np.int64).max:
                    df[col] = df[col].astype(np.int64)
            else:
                if c_min > np.finfo(np.float16).min and c_max < np.finfo(np.float16).max:
                    df[col] = df[col].astype(np.float16)
                elif c_min > np.finfo(np.float32).min and c_max < np.finfo(np.float32).max:
                    df[col] = df[col].astype(np.float32)
                else:
                    df[col] = df[col].astype(np.float64)
                    
    end_mem = df.memory_usage().sum() / 1024**2
    print('Memory usage after optimization is: {:.2f} MB'.format(end_mem))
    print('Decreased by {:.1f}%'.format(100 * (start_mem - end_mem) / start_mem))
    return df

本案例执行后代码可缩减12.5%

2  数据清洗

清晰必做的3个工作,处理缺失值、重复值、异常值

2.1  查看缺失值比例

df.isnull().mean()

 缺失率23%的字段:category_code,保留,固定值填充

# category_code本身为字符型,且缺失率在23% ,不宜直接删除,考虑用字符‘N’表示缺失进行填充
df['category_code'] = df['category_code'].fillna('N')

缺失率4%的字段:brand,删除缺失行

# 只保留非缺失行的数据
df = df[df.brand.notnull()]

2.2  查看重复值比例

df.duplicated().mean()
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

miracle2me

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值