黑色星期五銷售數(shù)據(jù)分析
1. 提出問題
數(shù)據(jù)分析不是為了分析而分析司澎,而是要通過數(shù)據(jù)分析來達到某種目的。對黑色星期五銷售數(shù)據(jù)進行分析籍滴,是希望通過數(shù)據(jù)分析來更好地了解客戶購買行為伙菜。
針對數(shù)據(jù)提供的信息甥角,主要從這幾個方面去分析:
- 年齡
- 性別
- 城市
- 居住城市年數(shù)
- 職業(yè)
- 婚姻狀況
- 商品和類別
前面6個是分析用戶畫像,最后一個是從商品的角度分析呼寸。
2. 數(shù)據(jù)理解
2.1 數(shù)據(jù)來源
數(shù)據(jù)集來自kaggle平臺的黑色星期五銷售數(shù)據(jù)Black-Friday艳汽,該數(shù)據(jù)集是零售商店中進行交易的樣本。
2.2 字段說明
該數(shù)據(jù)集總共包含12個字段对雪,如下:
序號 | 字段名 | 數(shù)據(jù)類型 | 字段描述 | 備注 |
---|---|---|---|---|
1 | User_ID | String | 用戶ID | |
1 | Product_ID | String | 商品ID | |
3 | Gender | String | 性別 | F:女河狐,M:男 |
4 | Age | String | 年齡 | 7個年齡段 |
5 | Occupation | String | 職業(yè) | 用0-20表示 |
6 | City_Category | String | 城市類別 | A,B,C |
7 | Stay_In_Current_City_Years | Integer | 居住城市年數(shù) | 0馋艺,1栅干, 2, 3捐祠, 4+ |
8 | Marital_Status | Integer | 婚姻狀況 | 0:已婚碱鳞,1:未婚 |
9 | Product_Category_1 | Integer | 產(chǎn)品類別1 |
2.3 數(shù)據(jù)探索
數(shù)據(jù)讀取
df = pd.read_csv('BlackFriday.csv')
查看行數(shù)和列數(shù)
df.shape
輸出:(537577, 12),537577行踱蛀,12列
查看索引窿给、數(shù)據(jù)類型和內(nèi)存信息
df.info()
Product_Category_2和Product_Category_2是存在空值的。
查看簡要的統(tǒng)計信息
df.describe()
查看10行數(shù)據(jù)
df.head(10)
3. 數(shù)據(jù)處理
列名重命名
為了方便看率拒,可以先對列名進行重命名成中文填大。
df = df.rename(columns={'User_ID': '用戶ID', 'Product_ID': '商品ID', 'Gender': '性別', 'Age': '年齡', 'Occupation': '行業(yè)', 'City_Category': '城市類別', 'Stay_In_Current_City_Years': '居住城市年數(shù)', 'Marital_Status': '婚姻狀況', 'Product_Category_1': '產(chǎn)品類別1', 'Product_Category_2': '產(chǎn)品類別2', 'Product_Category_3': '產(chǎn)品類別3', 'Purchase': '采購額'})
缺失值處理
(df.shape[0]- df.dropna(how='any').shape[0])/df.shape[0]
產(chǎn)品類別2和產(chǎn)品類別3是有缺失數(shù)據(jù)的,缺失是比例占69%俏橘,數(shù)據(jù)量太大允华,不能刪除,而且產(chǎn)品類別不好填充寥掐。但是因為在分析的過程中這兩個字段不進行分析靴寂,所以這里不管缺失值。
df_dd = df.drop_duplicates(subset=['用戶ID'])[['用戶ID', '性別', '年齡', '職業(yè)', '城市類別', '居住城市年數(shù)', '婚姻狀況']].sort_values(by='用戶ID')
df_dd['采購額'] = df.groupby('用戶ID')['采購額'].sum().sort_index().values
4. 數(shù)據(jù)分析
4.1 性別
explode = (0.1,0)
fig1, ax1 = plt.subplots(figsize=(10,7))
patches, texts, autotexts = ax1.pie(df_dd['性別'].value_counts(), explode=explode,labels=['男','女'], autopct='%1.1f%%',
shadow=True, startangle=90, colors=sns.color_palette("Blues_d", 2))
ax1.axis('equal')
plt.tight_layout()
plt.legend()
for t in texts:
t.set_size('xx-large')
for at in autotexts:
at.set_size('xx-large')
plt.legend(fontsize='16')
plt.show()
s_gender = df_dd.groupby('性別')['采購額'].sum().sort_values()
plt.figure(figsize=(12, 6))
plt.subplot(1, 1, 1)
sc = sns.color_palette("Blues_d", 2)
sns.barplot(s_gender.index, s_gender.values, palette=sc)
plt.xlabel('', fontsize=16)
plt.ylabel('', fontsize=16)
plt.xticks(np.arange(2), ('女', '男'))
plt.title('', fontsize=18)
plt.show()
從消費人數(shù)與消費金額兩個維度來看召耘,男性都遠遠超過女性百炬,這個結(jié)論與國內(nèi)男性、女性的消費存在很大的差異污它,有點出乎意料剖踊。
4.2 婚姻狀況
explode = (0.1, 0)
fig1, ax1 = plt.subplots(figsize=(10,7))
patches, texts, autotexts = ax1.pie(df_dd['婚姻狀況'].value_counts(), explode=explode, labels=['已婚','未婚'], autopct='%1.1f%%',
shadow=True, startangle=90, colors=sns.color_palette("Blues_d", 2))
ax1.axis('equal')
plt.tight_layout()
plt.legend(fontsize=18)
for t in texts:
t.set_size('xx-large')
for at in autotexts:
at.set_size('xx-large')
plt.legend(fontsize='16')
plt.show()
從圖中看,購買人群中已婚的要多于未婚的衫贬,結(jié)婚的生活需要購買的需要多一點德澈,可能家庭消費比較多。在進行營銷的時候固惯,要偏向于已婚人群梆造。
fig1, ax1 = plt.subplots(figsize=(12,7))
sc = sns.color_palette("Blues", 2)
sns.countplot(df_dd['婚姻狀況'],hue=df['性別'], palette=sc)
plt.xticks(np.arange(2), ('已婚', '未婚'))
plt.xlabel('', fontsize=16)
plt.ylabel('', fontsize=16)
plt.legend(fontsize=16)
plt.show()
可以再從性別的維度看,無論是已婚還是未婚葬毫,都是男性大于女性镇辉,不會受到婚姻狀況的影響。因為不知道當?shù)氐那闆r贴捡,無法下定結(jié)論就是女性沒有購買力忽肛。可以進一步調(diào)查烂斋,如果只是女性的市場沒有打開屹逛,嘗試提高女性購買的欲望础废,可能會有收獲。
4.3 年齡
fig1, ax1 = plt.subplots(figsize=(12,7))
sc = sns.color_palette("Blues", 2)
sns.countplot(df_dd['年齡'],hue=df['性別'], order=['0-17', '18-25', '26-35', '36-45', '46-50', '51-55', '55+'], palette=sc)
plt.xlabel('', fontsize=16)
plt.ylabel('', fontsize=16)
plt.legend(fontsize=16)
plt.show()
從年齡看煎源,無論是男性色迂,還是女性,消費人數(shù)都是集中18-45歲手销。其中26-35這個年齡段最多歇僧,這個年齡段的人消費能力大。
s_gender = df_dd.groupby('年齡')['采購額'].sum()
plt.figure(figsize=(10, 6))
plt.subplot(1, 1, 1)
sc = sns.color_palette("Blues_r", 8)
sns.barplot(s_gender.index, s_gender.values, order=['0-17', '18-25', '26-35', '36-45', '46-50', '51-55', '55+'], palette=sc)
plt.xlabel('', fontsize=16)
plt.ylabel('', fontsize=16)
plt.grid(axis='x')
plt.title('', fontsize=18)
plt.grid(axis='x')
plt.show()
消費金額的分布是跟購買人數(shù)的分布式一致的锋拖,都是集中在18-45歲诈悍,這個年齡區(qū)間的人購買力比較大。
4.4 城市
explode = (0.1, 0, 0)
fig1, ax1 = plt.subplots(figsize=(10,7))
patches, texts, autotexts = ax1.pie(df_dd['城市類別'].value_counts(), explode=explode,labels=df['城市類別'].unique(), autopct='%1.1f%%',
shadow=True, startangle=90, colors=sns.color_palette("Blues_r", 3))
ax1.axis('equal')
plt.tight_layout()
for t in texts:
t.set_size('xx-large')
for at in autotexts:
at.set_size('xx-large')
plt.legend(fontsize='16')
plt.show()
從購買的人數(shù)看兽埃,C城市人最多侥钳,A城市人最少。
explode = (0.1, 0, 0)
fig1, ax1 = plt.subplots(figsize=(10,7))
patches, texts, autotexts = ax1.pie(df_dd.groupby('城市類別')['采購額'].sum(), explode=explode,labels=df['城市類別'].unique(), autopct='%1.1f%%',
shadow=True, startangle=90, colors=sns.color_palette("Blues_r", 3))
ax1.axis('equal')
plt.tight_layout()
plt.legend()
for t in texts:
t.set_size('xx-large')
for at in autotexts:
at.set_size('xx-large')
plt.legend(fontsize='16')
plt.show()
從消費總額看柄错,A城市是最低的舷夺,C城市雖然購買人數(shù)超過一半,但是消費總額卻三分之一都不到售貌。
可以看出给猾,B城市的人購買力是最大的,購買的人數(shù)雖少颂跨,但是每個人的購買金額要大于其他兩個城市的人敢伸。其次是A城市,購買力最低的是C城市恒削,雖然C城市購買的人數(shù)要多于其他兩個城市池颈,但是消費總額卻低于其他兩個城市,可以看出A城市的購買力比較低钓丰。
hue_order=['0-17', '18-25', '26-35', '36-45', '46-50', '51-55', '55+']
order=['A', 'B', 'C']
fig1, ax1 = plt.subplots(figsize=(12,7))
sc = sns.color_palette("Blues_d", 7)
sns.countplot(df_dd['城市類別'],hue=df['年齡'], order=order, hue_order=hue_order, palette=sc)
plt.xlabel('', fontsize=16)
plt.ylabel('', fontsize=16)
plt.legend(fontsize=16)
plt.show()
從3個城市的年齡段分布看躯砰,A城市在各個年齡段的人數(shù)都是最少的,C城市高齡人數(shù)比較多斑粱。
4.5 居住城市年數(shù)
labels=['1年','2年','3年','4年以上','游客']
explode = (0.1, 0.1,0,0,0)
fig1, ax1 = plt.subplots(figsize=(10,7))
patches, texts, autotexts = ax1.pie(df_dd['居住城市年數(shù)'].value_counts(),explode=explode, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90, colors=sns.color_palette("Blues_d"))
sc = sns.color_palette("hls", 5)
sns.set_palette(sc)
ax1.axis('equal')
plt.tight_layout()
plt.legend(fontsize=16)
for t in texts:
t.set_size('xx-large')
for at in autotexts:
at.set_size('xx-large')
plt.show()
labels=['1年','2年','3年','4年以上','游客']
explode = (0.1, 0.1,0,0,0)
fig1, ax1 = plt.subplots(figsize=(10,7))
patches, texts, autotexts = ax1.pie(df_dd.groupby('居住城市年數(shù)')['采購額'].sum(), explode=explode, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90, colors=sns.color_palette("Blues_d"))
sc = sns.color_palette("hls", 5)
sns.set_palette(sc)
ax1.axis('equal')
plt.tight_layout()
plt.legend(fontsize=16)
for t in texts:
t.set_size('xx-large')
for at in autotexts:
at.set_size('xx-large')
plt.show()
從購買人數(shù)看弃揽,居住在城市第一年的購買人數(shù)是最多的,從消費總額看则北,第二年的人購買消費總額是最高的,但是購買人數(shù)是比第一年的人少痕慢。隨著居住年數(shù)的增加尚揣,購買的人數(shù)是遞減的。
居住在城市第二年的人消費人數(shù)和消費金額都是最高的掖举,其他都比較低快骗,對于居住2年的可以進行適當營銷,提高留存。
4.6 職業(yè)
fig1, ax1 = plt.subplots(figsize=(12,7))
x = df_dd['職業(yè)'].value_counts().sort_values().index
y = df_dd['職業(yè)'].value_counts().sort_values().values
sns.barplot(x, y, order=x, palette="Blues_d")
plt.xlabel('', fontsize=16)
plt.ylabel('', fontsize=16)
plt.show()
fig1, ax1 = plt.subplots(figsize=(12,7))
x = df_dd.groupby('職業(yè)')['采購額'].sum().sort_values().index
y = df_dd.groupby('職業(yè)')['采購額'].sum().sort_values().sort_values().values
sns.barplot(x, y, order=x, palette="Blues_d")
plt.xlabel('', fontsize=16)
plt.ylabel('', fontsize=16)
plt.show()
各職業(yè)的消費人數(shù)和消費總額排名大致一樣方篮,前三名都是4名秀、0、7藕溅,購買人數(shù)多匕得,消費總額高。根據(jù)購買人數(shù)的因素巾表,應(yīng)該把更多的商品針對購買職業(yè)人數(shù)多的職業(yè)汁掠。因為無法知道具體職業(yè)是什么,無從知道更多信息集币。
5. 結(jié)論
- 男性的消費人數(shù)和消費總額都遠超女性考阱,跟中國的男女購買情況有所差異。
- 已婚的購買人數(shù)比未婚的多鞠苟。
- 都是集中在18-45歲乞榨,這個年齡區(qū)間的人購買力比較大
- B城市的購買力最大,購買人數(shù)最多的并不一定是購買力最大的当娱。
- 購買人數(shù)隨著居住城市年數(shù)的增加而減少吃既,但是居住兩年的人消費總額是最高的。
- 各職業(yè)的消費總額跟購買人數(shù)相關(guān)趾访,職業(yè)人數(shù)差異還是比較大的态秧。