某电商运营类分析

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('ggplot')
plt.rcParams["font.sans-serif"]='SimHei'#解决中文乱码
plt.rcParams['axes.unicode_minus'] = False#解决负号无法正常显示的问题
# 数据读取
df = pd.read_excel(r"C:\Users\wxw\Downloads\online_retail_II.xlsx",sheet_name='Year 2010-2011',dtype=str)
df.head()
image.png
# 查看数据情况
df.info()
image.png
#重复值查看
a1 =df.shape[0]
df.drop_duplicates(inplace =True)
a2 =df.shape[0]
print('删除后记录量:',a2,'删除记录量:',a1-a2)
image.png
#充值索引
df.reset_index(drop =True,inplace =True)
# 缺失值处理
df.isnull().sum()
image.png
# 一致化处理
df['InvoiceDate'] = pd.to_datetime(df['InvoiceDate'],errors = 'coerce')
df['Quantity'] = df['Quantity'].astype('int32')
df['Price'] = df['Price'].astype('float')
df['Date'] = pd.to_datetime(df['InvoiceDate'].dt.date,errors = 'coerce')
df['Month'] = df['InvoiceDate'].astype('datetime64[M]')
df['Sales_volume'] = df['Quantity']*df['Price']
df.describe()
image.png
#删除 单价和数量为负值的数据
df = df[(df['Quantity'] > 0) & (df['Price'] > 0)]
df.describe()
image.png
# 查看现在数据表形式
df.head()
image.png
day =df.groupby('Date').aggregate({'Quantity':"sum",'Sales_volume':"sum"})
day.plot(figsize = (15,8))
plt.xlabel('每日')
plt.ylabel('数量')
plt.title('日度销售金额和单量趋势图')
image.png
# 取最高一周数据查看原因
day1 =day['2011-11-01':'2011-12-09']
day1.plot(figsize = (15,8))
plt.xlabel('日期')
plt.ylabel('数量')
plt.title('11月及12月销售金额和单量趋势图')
image.png
# 查看当天发生了什么
df[df.Date == '2011-12-09'].sort_values(by = 'Sales_volume', ascending = False).head(10)
image.png

有个大客户买了80995,这是导致数据异常的原因

month =df.groupby('Month').aggregate({'Quantity':"sum",'Sales_volume':"sum"})
month.plot(figsize = (15,8))
plt.xlabel('每月')
plt.ylabel('数量')
plt.title('月度销售金额和单量趋势图')
image.png
order_d = df.groupby('Invoice').aggregate({'Quantity':"sum",'Sales_volume':"sum"})
order_d.describe()
image.png
order_d['Quantity'].hist(bins = 100, figsize = (15, 8), color = 'r')
plt.title('订单量分布频率图')
plt.ylabel('频率')
plt.xlabel('订单量')
image.png
order_d[order_d.Quantity < 5000]['Quantity'].hist(bins = 100, figsize = (15, 8), color = 'r')
plt.title('订单量分布频率图(小于5000)')
plt.ylabel('频率')
plt.xlabel('订单量')
image.png
order_d['Sales_volume'].hist(bins = 100, figsize = (15, 8), color = 'r')
plt.title('销售金额分布频率图')
plt.ylabel('频率')
plt.xlabel('销售金额')
image.png
order_d[order_d.Sales_volume < 2000]['Sales_volume'].hist(bins = 100, figsize = (15, 8), color = 'r')
plt.title('销售金额分布频率图(小于2000英镑)')
plt.ylabel('频率')
plt.xlabel('销售金额')
image.png
plt.figure(figsize=(15,8))
plt.scatter(order_d['Quantity'], order_d['Sales_volume'], color = 'r')
plt.title('销售金额与订单量散点图')
plt.ylabel('销售金额')
plt.xlabel('订单量')
image.png
# 筛去商品件数在20000及以上的订单
plt.figure(figsize=(15,8))
plt.scatter(order_d[order_d.Quantity < 20000]['Quantity'], order_d[order_d.Quantity < 20000]['Sales_volume'], color = 'r')
plt.title('销售金额与订单量散点图(20000以下)')
plt.ylabel('销售金额')
plt.xlabel('订单量')
image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 今天,我终于和笑笑在一起了,笑笑是我姐姐家的孩子,她比我大三岁,但是,我们是最好的朋友,我有一段时间看不到她就想,...
    曹喆120423阅读 181评论 0 0
  • 就算没有人听到你的哭喊, 只能夜夜蜷缩在角落抽噎, 也请不要认为自己就此, 被世界的巨轮抛弃碾压。 地平线的彼端总...
    嗯_5d65阅读 202评论 0 1
  • 最近几天临汾天气不错,雾霾大大减少,我的心情也像近几天的天气一样,甚是明朗!近期好多客户朋友来到理财室,都会问我...
    梁志伟的小课桌阅读 1,572评论 7 8
  • ,我一个非常普通的女孩。 刚刚经历过高考 没有达到预期,但还是上了大学 但是我不知道为什么 在这漫长的假期间,我很...
    soSonySony阅读 279评论 0 1