这是来自《和鲸社区的一个》数据分析实战项目
原始链接为某电子产品销售数据分析报告及RFM模型
自己写的,用来练手
编辑器使用Vscode
这一部分是用户分析
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from pandas.core.reshape.pivot import pivot
#用户分析
#显示所有列
pd.set_option('display.max_columns', None)
#显示所有行
pd.set_option('display.max_rows', None)
#定义plt,绘图字体
matplotlib.rc("font",family='SimHei')
path=r'C:\Users\26053\Desktop\论文\Python\project_vscode\data_clean.csv'
data=pd.read_csv(path,index_col=0)
print(data.info())
#总GMV:商品交易总额
all_gmv=data['price_cnt'].sum()
print('总GMV:',all_gmv)
#每月的GMV
month_gmv=data.groupby('month')['price_cnt'].sum()
print('每月的GMV:\n',month_gmv)
plt.figure(num=1,figsize=(10,8))
month_gmv.plot()
#plt.show()
#客户单价
print('客户单价:')
all_gmv=data['price_cnt'].sum()
#nunique,返回唯一值的统计次数
all_user=data['user_id'].nunique()
print(round(all_gmv/all_user))
#每笔订单单价
print('每笔订单单价:')
all_order=data['order_id'].nunique()
print(round(all_gmv/all_order))
#用户总数量
print(all_user)
#各地区用户数量
al_local_user=data.groupby('local')['user_id'].nunique().reset_index()
al_local_user=al_local_user.rename(columns={
'user_id':'用户数量'})
al_local_user=al_local_user.sort_values(by='用户数量').reset_index(drop=True)
print(al_local_user)
print(type(al_local_user))
#创建柱状图
plt.figure(num=2,figsize=(10,8))
plt.bar(al_local_user['local'],al_local_user['用户数量'])
plt.title('各地区的用户数量')
plt.xlabel('地区')
plt.ylabel('用户数量')
for x,y in