一、研究背景
在当今竞争激烈的市场中,深入了解客户的行为习惯是零售和电子商务公司制定有效营销策略的关键。随着大数据技术的进步,企业能够收集大量与客户购买行为相关的数据,例如年龄、性别、购买频率、购买地点和产品偏好等。这些数据不仅可以帮助企业识别消费者的购买模式,还可以揭示影响购买决策的因素。通过对消费者行为的深入研究,企业可以优化产品推荐、精准广告投放,并制定有针对性的促销策略,以提高客户的购买体验和忠诚度。
二、研究意义
本研究旨在通过对客户购买行为数据的分析,揭示不同人口统计变量(如年龄、性别等)以及不同购买频率、购买品类等因素对消费者行为的影响。具体而言,本研究的意义包括以下几个方面:
-
促进个性化营销策略的制定:通过分析年龄、性别与购买偏好之间的关系,企业能够更好地为不同年龄段和性别的消费者制定个性化的推荐内容和促销活动,从而提高客户满意度。
-
支持库存管理和资源配置:通过对季节性消费模式的分析,企业可以提前规划库存和调整资源配置,避免因季节性需求波动导致的库存不足或积压。
-
提高客户生命周期价值:通过分析客户的购买频率和订阅状态,企业可以识别忠诚客户并制定激励措施,以提高客户的长期价值。
-
优化产品开发和改进:通过分析评价等级与购买金额的相关性,企业可以了解客户对不同产品的满意度,为后续产品开发和质量改进提供参考。
三、实证分析
数据集词汇表(按列)
客户 ID:分配给每个客户的唯一标识符,便于跟踪和分析他们随时间推移的购物行为。
年龄:客户的年龄,为细分和有针对性的营销策略提供人口统计信息。
性别:客户的性别认同是影响产品偏好和购买模式的关键人口统计变量。
购买的物品:客户在交易期间选择的特定产品或项目。
类别:所购商品所属的广泛分类或组(例如,服装、电子产品、杂货)。
购买金额(美元):交易的货币价值以美元 (USD) 表示,表示所购商品的成本。
位置:购买地点,提供对区域偏好和市场趋势的见解。
大小:与服装、鞋靴和某些消费品相关的所购商品的尺码规格(如适用)。
颜色:与所购商品关联的颜色变体或选择,影响买家偏好和商品供应情况。
季节:所购商品的季节性相关性(例如,春季、夏季、秋季、冬季),影响库存管理和营销策略。
评论评分:买家提供的关于他们对所购商品满意度的数字或定性评估。
订阅状态:指示客户是否选择了订阅服务,从而深入了解其忠诚度水平和经常性收入的潜力。
运输类型:指定用于配送所购商品的方式(例如,标准配送、快递),从而影响配送时间和费用。
应用折扣:指示是否对购买应用了任何促销折扣,从而阐明价格敏感性和促销效果。
使用的促销代码:记录交易过程中是否使用了促销代码或优惠券,有助于评估营销活动的成功。
以前的购买:提供有关客户先前购买的数量或频率的信息,有助于客户细分和保留策略。
付款方式:指定客户采用的付款方式(例如,信用卡、现金),提供对首选付款方式的见解。
购买频率:表示客户参与购买活动的频率,这是评估客户忠诚度和生命周期价值的关键指标。
导入数据分析包
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['font.sans-serif'] = ['KaiTi'] #中文
plt.rcParams['axes.unicode_minus'] = False #负号
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
###读取数据集
df = pd.read_csv('shopping_behavior_updated.csv')
查看数据前五行
查看缺失值
df.isnull().sum()
查看数据具体结构
查看数据类型
描述性统计分析(转置)
df.describe().T
查看AGE列的唯一值
df['Age'].sort_values().unique()
数据清洗,将错误的数据类型转换为正确的数据类
import pandas as pd
import matplotlib.pyplot as plt
# 设置图形质量参数
plt.rcParams['savefig.dpi'] = 300
plt.rcParams['figure.dpi'] = 300
plt.rcParams['agg.path.chunksize'] = 10000
# 按年龄段统计客户总数
total_customer_by_age_group = df['Age Group'].value_counts().sort_index()
colors = ['#FC4100', '#0056B3', '#FFC55A', '#9BC4F8', '#59D5E0']
# 将数据绘制为条形图
bars = total_customer_by_age_group.plot(kind='bar', color=colors, figsize=(20, 8))
plt.title('按年龄段细分的客户总数', fontsize=20)
plt.xlabel('年龄段', fontsize=16)
plt.xticks(rotation=0, ha='center')
plt.ylabel('客户总数', fontsize=16)
for bar in bars.patches:
height = bar.get_height()
bars.annotate(f'{height}',
(bar.get_x() + bar.get_width() / 2, height),
ha='center',
va='center',
xytext=(0, 5),
textcoords='offset points')
plt.show()
型
df['Purchase Amount (USD)'] = df['Purchase Amount (USD)'].astype(int)
df['Customer ID'] = df['Customer ID'].astype(str)
检查重复值
duplicated_data = df[df.duplicated()].sort_values('Customer ID', ascending=True)
数据可视化分析
分析按年龄段细分的客户总数
按年龄组:将客户细分为年龄组,以分析行为如何随年龄变化。
按性别: 探索男性和女性顾客之间的购买模式差异。
按购买频率:分析不同客户的购买频率,并将其分为每周、每两周、每季度等组。
根据年龄组和性别划分,客户总数是多少?
import pandas as pd
import matplotlib.pyplot as plt
# 设置图形质量参数
plt.rcParams['savefig.dpi'] = 300
plt.rcParams['figure.dpi'] = 300
plt.rcParams['agg.path.chunksize'] = 10000
# 按年龄组和性别统计客户总数
total_customer_by_age_group_and_gender = df.groupby(['Age Group'])['Gender'].value_counts().unstack()
colors = ['#FC4100', '#0056B3']
# 绘制数据为柱状图
bars = total_customer_by_age_group_and_gender.plot(kind='bar', color=colors, figsize=(20, 8))
# 添加标题
plt.title('按年龄组和性别细分的客户总数', fontsize=25)
plt.xlabel('年龄组', fontsize=25)
plt.xticks(rotation=0, ha='center')
plt.ylabel('客户总数', fontsize=25)
# 在每个柱子上方添加数据标签
for bar in bars.patches:
height = bar.get_height()
bars.annotate(f'{height}人',
(bar.get_x() + bar.get_width() / 2, height),
ha='center',
va='center',
xytext=(0, 5),
textcoords='offset points')
# 显示图形
plt.tight_layout()
plt.show()
按组龄划分的平均购买金额 (USD) 是多少?
# 设置图形质量参数以提高清晰度
plt.rcParams['savefig.dpi'] = 400
plt.rcParams['figure.dpi'] = 400
plt.rcParams['agg.path.chunksize'] = 10000
# 按年龄组计算平均购买金额(美元)
average_purchase_amount_by_age_group = df.groupby('Age Group')['Purchase Amount (USD)'].mean()
colors = ['#FC4100', '#0056B3', '#FFC55A', '#9BC4F8', '#59D5E0']
# 绘制数据为柱状图
bars = average_purchase_amount_by_age_group.plot(kind='bar', color=colors, figsize=(20, 8))
# 添加标题并设置字体大小为 25
plt.title('按年龄组细分的平均购买金额(美元)', fontsize=25)
plt.xlabel('年龄组', fontsize=25)
plt.xticks(rotation=0, ha='center', fontsize=25)
plt.ylabel('平均购买金额(美元)', fontsize=25)
# 在每个柱子上方添加数据标签
for bar in bars.patches:
height = bar.get_height()
bars.annotate(f'${height:.2f} 美元',
(bar.get_x() + bar.get_width() / 2, height),
ha='center',
va='center',
xytext=(0, 5),
textcoords='offset points', fontsize=20)
# 显示图形
plt.tight_layout()
plt.show()
不同年龄组别和性别的平均消费金额 (USD) 是多少?
按购买频率划分的平均购买金额 (USD) 是多少?
# 按购买频率计算平均购买金额(美元)
average_purchase_amount_by_purchase_fre = df.groupby('Frequency of Purchases')['Purchase Amount (USD)'].mean()
colors = ['#FC4100', '#0056B3', '#FFC55A', '#9BC4F8', '#59D5E0', '#FB773C', '#00712D']
# 绘制数据为柱状图
bars = average_purchase_amount_by_purchase_fre.plot(kind='bar', color=colors, figsize=(20, 8))
# 添加标题并设置字体大小为 25
plt.title('按购买频率细分的平均购买金额(美元)', fontsize=25)
plt.xlabel('购买频率', fontsize=25)
plt.xticks(rotation=0, ha='center', fontsize=25)
plt.ylabel('平均购买金额(美元)', fontsize=25)
# 在每个柱子上方添加数据标签
for bar in bars.patches:
height = bar.get_height()
bars.annotate(f'${height:.2f} 美元',
(bar.get_x() + bar.get_width() / 2, height),
ha='center',
va='center',
xytext=(0, 5),
textcoords='offset points', fontsize=20)
# 显示图形
plt.tight_layout()
plt.show()
按购买频率和性别划分的平均购买金额 (USD) 是多少?
购买趋势分析
按品类: 比较买家在不同品类上的花费。
按位置:调查购买行为和客户支出的地区差异。
按购买的商品: 查看衬衫、毛衣、牛仔裤等不同商品的受欢迎程度,以确定最畅销的商品。
# 绘制柱状图
bars = total_spend_by_categories.plot(kind='bar', color=colors, figsize=(20, 8))
# 添加标题并设置字体大小为 25
plt.title('不同产品类别的购买金额(美元)', fontsize=25)
plt.xlabel('产品类别', fontsize=25)
plt.xticks(rotation=0, ha='center', fontsize=25)
plt.ylabel('购买金额(美元)', fontsize=25)
# 在每个柱子上方添加数据标签
for bar in bars.patches:
height = bar.get_height()
bars.annotate(f'${height:,.2f} 美元',
(bar.get_x() + bar.get_width() / 2, height),
ha='center',
va='center',
xytext=(0, 5),
textcoords='offset points', fontsize=20)
# 显示图形
plt.tight_layout()
plt.show()
买家在按性别划分的不同品类上花费了多少钱?
# 按产品类别和性别统计总购买金额
total_spend_by_categories_and_gender = df.groupby(['Category', 'Gender'])['Purchase Amount (USD)'].sum().unstack()
colors = ['#FC4100', '#0056B3']
# 绘制柱状图
bars = total_spend_by_categories_and_gender.plot(kind='bar', color=colors, figsize=(20, 8))
# 添加标题并设置字体大小为 25
plt.title('按产品类别和性别统计的购买金额(美元)', fontsize=25)
plt.xlabel('产品类别', fontsize=25)
plt.xticks(rotation=0, ha='center', fontsize=25)
plt.ylabel('购买金额(美元)', fontsize=25)
# 在每个柱子上方添加数据标签
for bar in bars.patches:
height = bar.get_height()
bars.annotate(f'${height:,.2f} 美元',
(bar.get_x() + bar.get_width() / 2, height),
ha='center',
va='center',
xytext=(0, 5),
textcoords='offset points', fontsize=20)
# 显示图形
plt.tight_layout()
plt.show()
客户按年龄段在不同品类上花费多少钱?
# 添加标题并设置字体大小为 25
plt.title('按年龄组和产品类别统计的购买金额(美元)', fontsize=25)
plt.xlabel('年龄组', fontsize=25)
plt.xticks(rotation=0, ha='center', fontsize=25)
plt.ylabel('购买金额(美元)', fontsize=25)
# 在每个柱子上方添加数据标签
for bar in bars.patches:
height = bar.get_height()
bars.annotate(f'${height:,.0f} 美元',
(bar.get_x() + bar.get_width() / 2, height),
ha='center',
va='center',
color='#FFA1F5',
textcoords='offset points',
xytext=(0, -25),
rotation=90,
fontsize=20)
# 显示图形
plt.tight_layout()
plt.show()
客户根据位置花费多少?
plt.title('按地点统计的客户消费金额(美元)', fontsize=25)
plt.xlabel('地点', fontsize=25)
plt.xticks(rotation=90, fontsize=20)
plt.ylabel('购买金额(美元)', fontsize=25)
# 在每个柱子上方添加数据标签
for bar in bars.patches:
height = bar.get_height()
bars.annotate(f'${height:,.2f} 美元',
(bar.get_x() + bar.get_width() / 2, height),
ha='center',
va='center',
color='#ffffff',
xytext=(0, -30),
textcoords='offset points',
rotation=90,
fontsize=20)
# 显示图形
plt.tight_layout()
plt.show()
热门商品展示
定价和评论分析
购买金额与评论评级: 分析较高的购买金额是否与较好或较差的客户评级相关。
Discount Usage (折扣使用情况):比较应用了和不应用折扣的购买金额,并探索折扣是否推动了更多购买。
# 计算相关系数矩阵
purchase_amount_rating_correlation_matrix = df[['Purchase Amount (USD)', 'Review Rating']].corr()
# 创建热图
plt.figure(figsize=(20, 8))
sns.heatmap(purchase_amount_rating_correlation_matrix, annot=True, cmap='coolwarm', fmt='.2f', vmin=-1, vmax=1)
# 添加标题并设置字体大小为 25
plt.title('购买金额与评价等级的相关性热图', fontsize=25)
# 显示图形
plt.tight_layout()
plt.show()
热图将显示一个相关系数值范围为 -1 到 1 的矩阵。
1 表示完全正相关(当一个变量增加时,另一个变量按比例增加)。
-1 表示完全负相关(当一个变量增加时,另一个变量按比例减少)。
0 表示无相关性(变量之间没有线性关系)
购买金额 (美元) 和评论评级之间的高正相关系数接近 1 (0.85),表示较高的购买金额与较高的评论评级相关。
运输偏好和成本
配送类型分析: 根据配送类型比较购买金额和买家满意度。
购买金额与配送类型: 调查使用“快递”配送的买家是否比选择“免费配送”的买家花费更多。
plt.title('不同运输类型的平均评价等级', fontsize=25)
plt.xlabel('运输类型', fontsize=25)
plt.xticks(rotation=0, fontsize=20)
plt.ylabel('平均评价等级', fontsize=25)
# 在每个柱子上方添加数据标签
for bar in bars.patches:
height = bar.get_height()
bars.annotate(f'{height:.2f}',
(bar.get_x() + bar.get_width() / 2, height),
ha='center',
va='center',
xytext=(0, 5),
textcoords='offset points',
rotation=0,
fontsize=20)
# 显示图形
plt.tight_layout()
plt.show()
季节性购买模式
按季节:了解购买行为如何随不同季节(冬季、春季、夏季、秋季)而变化。例如,客户在冬天购买更多的衣服吗?
plt.figure(figsize=(20, 8))
# 添加标题并设置字体大小为 25
plt.title('按类别划分的季节性购买模式', fontsize=25)
plt.xlabel('季节', fontsize=20)
plt.ylabel('购买数量', fontsize=20)
# 循环遍历每个类别并绘制带有数据标签的图形
for category in seasonal_data['类别'].unique():
season_subset = seasonal_data[seasonal_data['类别'] == category]
plt.plot(season_subset['季节'], season_subset['购买数量'], label=category, marker='o')
# 添加数据标签,并调整位置以增加间距
for i in range(len(season_subset)):
plt.text(season_subset['季节'].iloc[i],
season_subset['购买数量'].iloc[i] + 10, # 调整 y 位置以增加间距
str(season_subset['购买数量'].iloc[i]),
fontsize=15,
ha='center',
va='bottom', # 调整为更好的对齐方式
color='black')
# 添加图例
plt.legend(fontsize=18)
# 显示图形
plt.tight_layout()
plt.show()
四、研究结论
本研究通过对消费行为数据的分析,得出以下主要结论:
-
年龄和性别对消费偏好的影响:数据分析显示,不同年龄段和性别的消费者在消费金额、购买品类等方面存在显著差异。例如,年轻消费者更倾向于购买时尚产品,而年长消费者在电子产品等领域的消费较为集中。此外,女性在服装、化妆品等品类上的消费金额高于男性,而男性在电子产品上的消费占比相对较高。
-
购买频率与客户忠诚度的关联:高频率购买的客户通常表现出更高的忠诚度,而这些客户也更倾向于参与公司推出的促销活动和订阅服务。企业可以通过激励措施,增强这些客户的忠诚度,并推动其他客户提高购买频率。
-
季节性消费模式的规律:不同品类的商品在不同季节的销售情况存在较大差异,例如,服装的销售在冬季和夏季达到高峰,而电子产品的销售在节假日季节(如年底)显著增加。企业可据此提前准备,调整库存管理和资源分配,以更好地满足季节性需求。
-
折扣和促销对购买决策的影响:折扣的应用在一定程度上提升了销售额,尤其是在价格敏感度较高的消费者群体中。分析结果还显示,折扣和促销活动对于某些品类(如日常消费品)的销售效果尤为显著。
综上所述,本研究揭示了客户在年龄、性别、购买频率、季节等维度上的行为特征,为企业优化营销策略、提升客户忠诚度和改善库存管理提供了数据支持。这些分析结果可为企业在制定长期战略规划时提供有价值的参考。