欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

基于Python的某电商平台交易数据分析

程序员文章站 2024-03-07 18:17:51
...

基于Python的某电商平台交易数据分析

分析框架:

1.数据解读
1.1导入数据
1.2数据读取
2.数据清洗
3.交易数据特征分析
3.1 商品维度
3.2 用户维度
3.3 城市维度
3.4 价格维度
3.5 渠道维度
3.6 时间维度

1.数据解读

1.1导入数据

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df=pd.read_csv(r'D:\order_info_2016.csv',index_col='id')

df['payMoney']=df['payMoney']/100
df['price']=df['price']/100
df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 104557 entries, 47510 to 10889
Data columns (total 10 columns):
 #   Column      Non-Null Count   Dtype  
---  ------      --------------   -----  
 0   orderId     104557 non-null  int64  
 1   userId      104557 non-null  int64  
 2   productId   104557 non-null  int64  
 3   cityId      104557 non-null  int64  
 4   price       104557 non-null  float64
 5   payMoney    104557 non-null  float64
 6   channelId   104549 non-null  object 
 7   deviceType  104557 non-null  int64  
 8   createTime  104557 non-null  object 
 9   payTime     104557 non-null  object 
dtypes: float64(2), int64(5), object(3)
memory usage: 8.8+ MB

1.2 数据解读

这是一组以订单ID为唯一数据标签,诠释每张订单的产品/用户/渠道/成交价和交易时间的二维关系表。此数据集共包含104557行,包含以下10项字段:
Data columns (total 10 columns):
Column Non-Null Count Dtype 含义 注释


0 orderId 104557 non-null int64 订单ID 九位数字组成
1 userId 104557 non-null int64 用户ID 六位数字组成
2 productId 104557 non-null int64 产品ID 0-1000的数字
3 cityId 104557 non-null int64 城市的ID 5-6位数字组成
4 price 104557 non-null int64 标价 非0数值
5 payMoney 104557 non-null int64 成交价 数值(亦可以<0)
6 channelId 104549 non-null object 渠道ID 由英文字母和数字构成
7 deviceType 104557 non-null int64 设备类型 1-6代表六种不同的设备
8 createTime 104557 non-null object 订单创建时间 2015-2016的时间
9 payTime 104557 non-null object 订单支付时间 2015-2016的时间 不可以早于订单创建时间

2.数据清洗

#orderid预处理
# df['orderId'].value_counts(dropna=False)
df['orderId'].unique().size
#说明有27条重复的,暂不处理
104530
#userid预处理,可以重复 但必须是数值
print(df['userId'].describe())
print(df['userId'].dtype)
#userid不需要处理
count    1.045570e+05
mean     3.270527e+06
std      4.138208e+07
min      2.930600e+04
25%      2.179538e+06
50%      2.705995e+06
75%      3.271237e+06
max      3.072939e+09
Name: userId, dtype: float64
int64
#productId预处理,是否有空值,可以重复 但必须是数值,0-1000之间均可,为0亦不作处理
print(df['productId'].describe())
count    104557.000000
mean        504.566275
std         288.130647
min           0.000000
25%         254.000000
50%         507.000000
75%         758.000000
max        1000.000000
Name: productId, dtype: float64
#cityId预处理,是否有空值,可以重复 但必须是数值
df['cityId'].describe()
count    104557.000000
mean     154410.947225
std       72197.163762
min       30000.000000
25%      100011.000000
50%      150001.000000
75%      220002.000000
max      380001.000000
Name: cityId, dtype: float64
#price预处理,是否有空值,是否有负值
df['price'].describe()
count    104557.000000
mean        916.734987
std         915.883592
min           6.000000
25%         379.000000
50%         592.000000
75%        1080.000000
max       22956.000000
Name: price, dtype: float64
#payMoney预处理,是否有空值,是否有负值
print(df['payMoney'].describe())
print(df[df['payMoney']<0].index)#负值可能代表退货,这里只有六行,无法用于对退货商品进行分析
df.drop(index=df[df['payMoney']<0].index,inplace=True)#样本量足够直接删除这六行以避免对分析造成影响
count    104557.000000
mean        868.668948
std         907.202848
min         -10.000000
25%         336.000000
50%         550.000000
75%        1040.000000
max       22942.000000
Name: payMoney, dtype: float64
Int64Index([66897, 87878, 81494, 72556, 25344, 55044], dtype='int64', name='id')
#channelID预处理,是否有空值
print(df[df['channelId'].isnull()])#有8行数据是channelId为空的
df.drop(index=df[df['channelId'].isnull()].index,inplace=True)#把channelId为空的记录删除
          orderId   userId  productId  cityId   price  payMoney channelId  \
id                                                                          
19086   284008366  3309847        698  240001  2164.0    2040.0       NaN   
38175   287706890  2799815        823   70001   760.0     749.0       NaN   
100952  283627429  4156620        269  280001   484.0     410.0       NaN   
48073   248057459  3970570        142  130001   474.0     400.0       NaN   
100954  352853915  2229389        786  240001   474.0     440.0       NaN   
75949   266847859  3761925        649  120006   257.0     257.0       NaN   
100955  379473081  4531810         18  180009   146.0      50.0       NaN   
100953  346836140  3751526        738  100013   105.0      80.0       NaN   

        deviceType        createTime           payTime  
id                                                      
19086            2    2016/3/8 22:36    2016/3/8 22:36  
38175            3   2016/6/10 22:30   2016/6/10 22:30  
100952           2  2016/12/13 13:24  2016/12/13 14:47  
48073            2   2016/3/30 12:59   2016/3/30 12:59  
100954           2  2016/12/13 16:54  2016/12/13 16:55  
75949            2    2016/8/19 8:46    2016/8/19 8:46  
100955           3  2016/12/13 20:18  2016/12/13 20:18  
100953           1  2016/12/13 13:47  2016/12/13 13:47  
#deviceType预处理,从1-6
print(df['deviceType'].describe())
df['deviceType'].value_counts()
# df.info()
count    104543.000000
mean          2.385325
std           0.648467
min           1.000000
25%           2.000000
50%           2.000000
75%           3.000000
max           6.000000
Name: deviceType, dtype: float64





2    52440
3    42944
1     7052
4     2017
6       87
5        3
Name: deviceType, dtype: int64
#createTime payTime预处理
print(df['createTime'].dtype)#查看格式
df['createTime']=pd.to_datetime(df['createTime'])#createTime/payTime都转换成时间格式
df['payTime']=pd.to_datetime(df['payTime'])

object
#时间早于2016年的删除
import datetime
startime1=datetime.datetime(2016,1,1)
endtime1=datetime.datetime(2016,12,31,23,59,59)
# startime2=datetime.datetime('2016-1-1')
# endtime2=pd.to_datetime('2016-12-31')
df[df['createTime']<startime1]
df.drop(index=df[df['createTime']<startime1].index,inplace=True)#把时间早于2016年的删除

#支付时间早于创建时间,删除
df[df['payTime']<df['createTime']]
df.drop(index=df[df['payTime']<df['createTime']].index,inplace=True)

df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 104533 entries, 47510 to 10889
Data columns (total 10 columns):
 #   Column      Non-Null Count   Dtype         
---  ------      --------------   -----         
 0   orderId     104533 non-null  int64         
 1   userId      104533 non-null  int64         
 2   productId   104533 non-null  int64         
 3   cityId      104533 non-null  int64         
 4   price       104533 non-null  float64       
 5   payMoney    104533 non-null  float64       
 6   channelId   104533 non-null  object        
 7   deviceType  104533 non-null  int64         
 8   createTime  104533 non-null  datetime64[ns]
 9   payTime     104533 non-null  datetime64[ns]
dtypes: datetime64[ns](2), float64(2), int64(5), object(1)
memory usage: 8.8+ MB
#还剩下orderId重复的27行,因为样本量足够,删除重复的
df['orderId'].unique().size
df.drop(index=df[df['orderId'].duplicated()].index,inplace=True)
#df.drop_duplicates(subset='orderId', keep='first', inplace=True)#另一种方法
df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 104506 entries, 47510 to 10889
Data columns (total 10 columns):
 #   Column      Non-Null Count   Dtype         
---  ------      --------------   -----         
 0   orderId     104506 non-null  int64         
 1   userId      104506 non-null  int64         
 2   productId   104506 non-null  int64         
 3   cityId      104506 non-null  int64         
 4   price       104506 non-null  float64       
 5   payMoney    104506 non-null  float64       
 6   channelId   104506 non-null  object        
 7   deviceType  104506 non-null  int64         
 8   createTime  104506 non-null  datetime64[ns]
 9   payTime     104506 non-null  datetime64[ns]
dtypes: datetime64[ns](2), float64(2), int64(5), object(1)
memory usage: 8.8+ MB

3.交易数据特征分析

3.1商品维度

商品维度分析首先得出了年订单量最高/最低的前十种商品,各类商品吸引的用户数,年销售额前十的商品等,主要分析结论有:

1.订单量前十的商品和吸引用户数前十的商品一致,用户的人均下单次数 1.02次,说明用户购买的重复率不是影响各类商品最终订单量的主要因素;

2.各类商品平均每单销售额最低的是商品964,金额是365.08元,最高的是商品270,金额是2635.34元,平均值是905.64元,说明各类商品的每单成交均价较高, 非薄利多销的低价值商品;

3.以下编号商品无论是年销售额还是年订单量都排在后100位,对该电商平台2016年总销售额贡献较小,如无特殊的推广价值,建议下架: Int64Index([16, 621, 478, 310, 454, 597, 986, 1000, 347], dtype=‘int64’, name=‘productId’)

#商品的平均下单量与销售额
print('总商品数是:',df['productId'].unique().size)
print('每种商品平均下单量:',int(df['orderId'].count()/df['productId'].unique().size),'次')
print('每种商品平均销售额:',df['payMoney'].sum()/df['productId'].unique().size,'元')
总商品数是: 1001
每种商品平均下单量: 104 次
每种商品平均销售额: 90713.82927072929 元

(1)各类商品的订单量

#订单量最高/最低的前十种商品
product_order_sum=df.groupby('productId').count().sort_values('orderId',ascending=False)['orderId']
product_head=product_order_sum.head(10)#销量前十
product_head.plot(kind='bar',alpha=1.0,rot=30,title='Product_top10')
# print('前100的商品订单数总和占总订单数的比例:',product_order_sum.head(500).sum()/product_order_sum.sum())

基于Python的某电商平台交易数据分析

product_tail=df.groupby('productId').count().sort_values('orderId',ascending=False)['orderId'].tail(10)#订单量后十
product_tail.plot(kind='bar',alpha=1.0,rot=30,title='Product_last10')

基于Python的某电商平台交易数据分析

(2)各类商品吸引的用户数


groupby_productId_userId1=df.groupby('productId').userId.nunique().sort_values(ascending=False).head(10)#去重后计数
groupby_productId_userId1.plot(kind='bar',alpha=1.0,rot=30,title='Number of users per category--top10')
print('人均下单次数',df['payMoney'].count()/df['userId'].unique().size)#人均下单次数
人均下单次数 1.018368560041317

基于Python的某电商平台交易数据分析

(3)各类商品的销售额

#不同种商品的总销售额
groupby_productId_payMoney=df.groupby('productId').sum()['payMoney'].sort_values(ascending=False)
groupby_productId_payMoney.head(10).plot(kind='bar',alpha=1.0,rot=30,title='Total sales of each category_top10')

基于Python的某电商平台交易数据分析

(4)各类商品平均每单的销售额

#不同种商品的每单平均销售额
groupby_productId_payMoney_mean=df.groupby('productId').mean()['payMoney'].sort_values(ascending=False)
groupby_productId_payMoney_mean.head(10).plot(kind='bar',alpha=1.0,rot=30,title='Average sales per order of each category_top10')
print('各类商品平均每单销售额最低的是:',groupby_productId_payMoney_mean.tail(1))
print('各类商品平均每单销售额最高的是:',groupby_productId_payMoney_mean.head(1))
print('各类商品平均每单销售额的平均值是:',groupby_productId_payMoney_mean.mean())
各类商品平均每单销售额最低的是: productId
964    365.076923
Name: payMoney, dtype: float64
各类商品平均每单销售额最高的是: productId
270    2635.339286
Name: payMoney, dtype: float64
各类商品平均每单销售额的平均值是: 905.6393379189589

基于Python的某电商平台交易数据分析

(5)建议下架的商品

#根据销售额后100和销量后100的交集求出问题商品
problem_product=groupby_productId_payMoney.tail(20).index.intersection(product_order_sum.tail(20).index)
print('以下商品建议下架:',problem_product)
以下商品建议下架: Int64Index([16, 621, 478, 310, 454, 597, 986, 1000, 347], dtype='int64', name='productId')

3.2 用户维度

用户维度分析结论:
1.2016年平台吸引的总计用户数(去重)为102621人,人均消费总额 884.85 元,每位用户的年下单次数均值为 1.02次/人,用户不倾向于重复购买,所以用户群体的大小是决定最终销售额的关键,建议加大推广力度引入新用户;

单次消费均值最大的用户的消费额为22942.0 元,单次消费均值最小的用户的消费额为0.0 元;

2.用户平均每单成交价主要集中在200元-600元;

3.98%以上的用户2016这一年只在该平台购买一次商品;

#用户数
print('16年吸引的总计用户数(去重):',df['userId'].unique().size)#16年吸引的总计用户数(去重)
print('人均下单次数',df['payMoney'].count()/df['userId'].unique().size)#人均下单次数
print('人均消费总额',df['payMoney'].sum()/df['userId'].unique().size,'元')#人均消费总额
print('单次消费均值最大额:',df.groupby('userId').mean()['payMoney'].sort_values(ascending=False).max(),'元')
print('单次消费均值最小额:',df.groupby('userId').mean()['payMoney'].sort_values(ascending=False).min(),'元')
16年吸引的总计用户数(去重): 102621
人均下单次数 1.018368560041317
人均消费总额 884.853422788708 元
单次消费均值最大额: 22942.0 元
单次消费均值最小额: 0.0 元

(1)用户平均每单成交价分布情况

user_payMoney_mean=df.groupby('userId').mean()['payMoney'].sort_values(ascending=False)
bins1=np.arange(0,23000,200)
price_cut=pd.cut(user_payMoney_mean,bins=bins1).value_counts().sort_values(ascending=False)
print(price_cut.head(20))
price_cut.head(10).plot(kind='bar',alpha=1.0,rot=30,title='')
(200, 400]      22045
(400, 600]      21670
(600, 800]      13812
(0, 200]        11370
(800, 1000]      6034
(1000, 1200]     5574
(1600, 1800]     3771
(1200, 1400]     3185
(1800, 2000]     2984
(2000, 2200]     2360
(1400, 1600]     2336
(2600, 2800]     1462
(2800, 3000]     1056
(3000, 3200]      966
(2400, 2600]      745
(2200, 2400]      664
(3800, 4000]      502
(4000, 4200]      405
(3600, 3800]      372
(3200, 3400]      223
Name: payMoney, dtype: int64

基于Python的某电商平台交易数据分析

(2)每位用户一年下单数分布

user_orderId_mean=df.groupby('userId').count()['orderId'].sort_values(ascending=False)
# user_orderId_mean.max()#最多的是三次
bins2=np.arange(0,4,1)
order_num_cut=pd.cut(user_orderId_mean,bins=bins2).value_counts().sort_values(ascending=False)
# order_num_cut.plot(kind='bar',alpha=1.0,rot=30)
order_num_cut.plot(kind='pie',autopct='%d%%',shadow=True,figsize=(10,10))

基于Python的某电商平台交易数据分析

3.3 城市维度

城市维度分析结论是:

1.2016年总共有来自331座城市的用户在该平台购买商品,其中下单数最多的城市编号为110001,这座城市销售总额亦是最高;

2.活跃度最高(订单量和销售额均位列前十)的城市的编号是:[110001, 220002, 130001, 220005, 60011, 40001, 120001, 70001,230001],建议集中火力促进这些城市的留存和纳新,进一步扩大品牌的独特优势。

3.活跃度最低(订单量和销售额均位列后十)的城市的编号是:[310005, 280010, 380001, 280012],可以考虑投入更多的财力物力在这些城市中开辟市场,或者根据平台的战略需要暂缓对这些城市投入过多的推广运营成本。

(1)各城市的订单总数分布

#城市总数
df['cityId'].unique().size#一共涉及331座城市
331
#不同城市的订单总数分布
groupby_cityId_orderId=df.groupby('cityId').count().sort_values('orderId',ascending=False)['orderId']
groupby_cityId_orderId.head(10).plot(kind='bar',alpha=1.0,rot=30)

基于Python的某电商平台交易数据分析

(2)各城市的销售额分布

#不同城市的销售额
groupby_cityId_payMoney=df.groupby('cityId').sum().sort_values('payMoney',ascending=False)['payMoney']
groupby_cityId_payMoney.head(10).plot(kind='bar',alpha=1.0,rot=30)

基于Python的某电商平台交易数据分析

(3)活跃度高的十大城市

#活跃度高的城市
developed_city=groupby_cityId_payMoney.head(10).index.intersection(groupby_cityId_orderId.head(10).index)
developed_city
Int64Index([110001, 220002, 130001, 220005, 60011, 40001, 120001, 70001,
            230001],
           dtype='int64', name='cityId')

(4)活跃度最低的十大城市

#活跃度低的城市
developing_city=groupby_cityId_payMoney.tail(10).index.intersection(groupby_cityId_orderId.tail(10).index)
developing_city
Int64Index([310005, 280010, 380001, 280012], dtype='int64', name='cityId')

3.4 价格维度

价格维度分析结论:
1.该平台所有商品的价格区间在6.0-22956.0元之间,平均值为916.93元;

2.价格在300-500元之间的订单量最大,同时吸引的用户数最多;

3.在0-23000之间间隔为100元的价格区间中仍有很多价格区间内不存在售卖商品;

(1)总体价格区间

print(df['price'].max())
print(df['price'].min())
print(df['price'].mean())
22956.0
6.0
916.9345779189712

(2)不同价格区间的订单总数

#############################################
#price维度:
#不同价格区间的订单总数
# df.price.describe()
bins=np.arange(0,23000,100)
price_cut=pd.cut(df.price,bins=bins).value_counts()
price_cut.head(10).plot(kind='bar',alpha=1.0,rot=30)

# # price_cut.tail(50)
# price_cut_group=df.groupby(price_cut).count()['orderId']
# price_cut_group

基于Python的某电商平台交易数据分析

# plt.figure(figsize=(16,16))
# plt.hist(df['price'],bins)

(3)找到没有商品的价格区间

#找到没有商品的价格区间 
price_cut_count=pd.cut(df.price,bins).value_counts()
zero_cut_result=(price_cut_count==0)
price_cut_count[zero_cut_result.values].index
CategoricalIndex([(10800, 10900], (10700, 10800], (10600, 10700],
                  (10500, 10600], (10400, 10500], (10300, 10400],
                  (10200, 10300],   (7300, 7400],   (7400, 7500],
                    (9700, 9800],
                  ...
                  (15400, 15500], (15300, 15400], (15200, 15300],
                  (15100, 15200], (15000, 15100], (14900, 15000],
                  (14800, 14900], (14700, 14800], (14600, 14700],
                  (11400, 11500]],
                 categories=[(0, 100], (100, 200], (200, 300], (300, 400], (400, 500], (500, 600], (600, 700], (700, 800], ...], ordered=True, dtype='category', length=134)

(4)不同价格区间吸引的用户总数

#不同价格区间吸引的用户总数
bins=np.arange(0,23000,100)
price_cut2=pd.cut(df.price,bins=bins)
price_cut_userId=df.groupby(price_cut2).userId.nunique().sort_values(ascending=False)
price_cut_userId.head(10).plot(kind='bar',alpha=1.0,rot=30)
#******分布情况与不同价格区间的订单总数一致,说明对于不同价格区间的订单总数和吸引的用户总数之间可能会存在一定的正相关关系

基于Python的某电商平台交易数据分析

3.5 渠道维度

1.订单量最高的渠道是9058255c90,仅此渠道的订单量占总订单量的37%以上;

2.渠道9058255c90每年转化的销售额亦是所有渠道中最高的,占总销售额的38%以上。

(1)各渠道的订单数

df['channelId'].unique().size#一共涉及633个渠道
633
#年订单总数前十
groupby_channelId_order_count=df.groupby(df['channelId']).count().sort_values('orderId',ascending=False)['orderId']
groupby_channelId_order_count.head(10).plot(kind='bar',alpha=1.0,rot=30)
percentage_top1=groupby_channelId_order_count.head(1).values/df['orderId'].count()#订单量最高的渠道占总订单量的比值
percentage_top1
groupby_channelId_order_count.head(1)
channelId
9058255c90    38883
Name: orderId, dtype: int64

基于Python的某电商平台交易数据分析

#每年引入的订单数不足10单渠道数
groupby_channelId_order_count[groupby_channelId_order_count<=10].size#432个(超过一半)的渠道每年引入的订单数不足10单
432

(2)各渠道每年转化的销售额

#每个渠道每年转化的销售额
groupby_channelId_order_sum=df.groupby(df['channelId']).sum().sort_values('payMoney',ascending=False)['payMoney']
groupby_channelId_order_sum.head(10)#每年转化销售总额排名前十的渠道和每年转化订单总数排名前十的渠道基本一致
groupby_channelId_order_sum.head(10).plot(kind='bar',alpha=1.0,rot=30)
groupby_channelId_order_sum.head(1).values/groupby_channelId_order_sum.sum()
array([0.38003004])

基于Python的某电商平台交易数据分析

3.6 时间维度

时间维度分析结论:

1.一天中的下单高峰时段有两个,分别是中午的12:00-15:00间,和晚间的19:00-22:00间;

2.一周中的下单高峰在周五和周六,周五的13:00-15:00和周六的13:00-15:00是一周中的下单高峰时段;

3.关于订单成交的犹豫时间(下单时间与支付时间之间的间隔):95%以上的订单10分钟之内就完成了支付,69%以上的订单下单后1分钟内即完成支付,用户的犹豫时间不长;

4.每月销售额波动较大,其均值是: 7567045.26元,其中7月份销售额最大,为9417064.8元,11月份最小,为4867545.0元。

(1) 下单高峰时段

##############################################
#creaTime维度:哪些时段下单量大
#一天中的高峰
df['orderHour']=df['payTime'].dt.hour
df['orderHour']
groupby_orderHour_order=df.groupby(df['orderHour']).count()['orderId']
groupby_orderHour_order.plot(kind='bar',alpha=1.0,rot=30)

基于Python的某电商平台交易数据分析

#一周中的高峰
df['orderWeekday']=df['payTime'].dt.dayofweek
# df['orderWeekday']
groupby_orderWeekday_order=df.groupby(df['orderWeekday']).count()['orderId'].sort_values(ascending=False)
groupby_orderWeekday_order.plot(kind='bar',alpha=1.0,rot=30)

基于Python的某电商平台交易数据分析

#周几的哪个时段最活跃:
groupby_orderWeekday_hour_order=df.groupby(['orderWeekday','orderHour']).count().sort_values('orderId',ascending=False).head(4)
groupby_orderWeekday_hour_order    
orderId userId productId cityId price payMoney channelId deviceType createTime payTime
orderWeekday orderHour
5 13 2689 2689 2689 2689 2689 2689 2689 2689 2689 2689
6 13 2603 2603 2603 2603 2603 2603 2603 2603 2603 2603
14 2103 2103 2103 2103 2103 2103 2103 2103 2103 2103
5 14 2065 2065 2065 2065 2065 2065 2065 2065 2065 2065

(2) 下单后多久支付(犹豫时间)

##############################################
#payTime维度:下单后多久支付
def get_seconds(x):
    return x.total_seconds()
df['payDelta']=(df.payTime-df.createTime).apply(get_seconds)#用apply把时间单位转化为s
bins3=[0,60,600,6000,60000,600000]
payDelta_cut=pd.cut(df.payDelta,bins=bins3).value_counts()
payDelta_cut.plot(kind='bar',alpha=1.0,rot=30)
#*****初步结论是95%以上的下订单10分钟之内就完成了支付

基于Python的某电商平台交易数据分析

payDelta_cut.plot(kind='pie',autopct='%d%%',shadow=True,figsize=(10,10))

基于Python的某电商平台交易数据分析

(3) 各月销售额

#月成交额-方法1
#用dt.month把月份都提取出来,再用月份分组求和,取其中payMoney的和
df['orderMonth']=df.payTime.dt.month
groupby_orderMonth_payMoney=df.groupby('orderMonth').sum()['payMoney']
groupby_orderMonth_payMoney.plot(alpha=1.0,rot=30)
# sns.distplot(groupby_orderMonth_payMoney,color="g")
# 夏季678月份销售额最高
print('每月销售额均值是:',groupby_orderMonth_payMoney.mean())
print('每月销售额均最大值是:',groupby_orderMonth_payMoney.max())
print('每月销售额均最小值是:',groupby_orderMonth_payMoney.min())
每月销售额均值是: 7567045.258333336
每月销售额均最大值是: 9417064.800000003
每月销售额均最小值是: 4867545.000000001

基于Python的某电商平台交易数据分析

# # 月成交额--方法2
# # 把cratime设为索引,再用resample('M').sum()['payMoney']提取出每月的
# df.set_index('createTime',inplace=True)
# turnover=df.resample('M').sum()['payMoney']
# # order_count=df.resample('M').count()['orderId']
# turnover.plot()

(4) 各月成交订单数

#每月订单数
groupby_orderMonth_orderId=df.groupby('orderMonth').count()['orderId']
groupby_orderMonth_orderId.plot(alpha=1.0,rot=30)

基于Python的某电商平台交易数据分析

df.corr()
orderId userId productId cityId price payMoney deviceType orderHour orderWeekday payDelta orderMonth
orderId 1.000000 0.004933 -0.001019 0.006481 0.000463 0.005618 -0.004119 0.001213 -0.000345 0.000321 0.512146
userId 0.004933 1.000000 0.000833 -0.023018 0.002307 0.002596 0.032302 -0.001631 -0.003119 -0.000234 0.011987
productId -0.001019 0.000833 1.000000 -0.025191 -0.013348 -0.013156 0.012936 0.011202 0.005171 -0.000044 0.007925
cityId 0.006481 -0.023018 -0.025191 1.000000 -0.000416 -0.001482 -0.033930 0.014332 -0.000604 0.004588 0.011055
price 0.000463 0.002307 -0.013348 -0.000416 1.000000 0.996381 0.074583 0.271853 -0.024382 -0.006224 0.009063
payMoney 0.005618 0.002596 -0.013156 -0.001482 0.996381 1.000000 0.075631 0.271791 -0.024301 -0.005879 0.018608
deviceType -0.004119 0.032302 0.012936 -0.033930 0.074583 0.075631 1.000000 0.033384 -0.014770 -0.006097 -0.013324
orderHour 0.001213 -0.001631 0.011202 0.014332 0.271853 0.271791 0.033384 1.000000 -0.051085 -0.008108 -0.000255
orderWeekday -0.000345 -0.003119 0.005171 -0.000604 -0.024382 -0.024301 -0.014770 -0.051085 1.000000 -0.000137 -0.000471
payDelta 0.000321 -0.000234 -0.000044 0.004588 -0.006224 -0.005879 -0.006097 -0.008108 -0.000137 1.000000 0.021903
orderMonth 0.512146 0.011987 0.007925 0.011055 0.009063 0.018608 -0.013324 -0.000255 -0.000471 0.021903 1.000000
month_detail=pd.DataFrame()
month_detail['payMoney']=df.groupby('orderMonth').sum()['payMoney']
month_detail['order_num']=df.groupby('orderMonth').count()['orderId']
month_detail['user_num']=df.groupby('orderMonth').userId.nunique()
df['discount']=df['price']-df['payMoney']
month_detail['discount']=df.groupby('orderMonth').sum()['discount']
month_detail.plot()

基于Python的某电商平台交易数据分析

***数据来自于某知乎用户的分享,已做过脱敏处理