国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

18143453325 在線咨詢 在線咨詢
18143453325 在線咨詢
所在位置: 首頁(yè) > 營(yíng)銷資訊 > 電子商務(wù) > python電商行業(yè)數(shù)據(jù)分析

python電商行業(yè)數(shù)據(jù)分析

時(shí)間:2023-03-16 00:58:01 | 來源:電子商務(wù)

時(shí)間:2023-03-16 00:58:01 來源:電子商務(wù)

我是一個(gè)從事商業(yè)地產(chǎn)5年的“中青年”每天起床都會(huì)對(duì)各種數(shù)據(jù)做思維上研究,最近廣東的天氣可是活了那么多年的我遇到最冷冬天,最冷的辦公室,我忍不住上了某寶平臺(tái)上買了“小太陽”結(jié)果還跟同事拼起了單,嘻~同時(shí)也想著最近幾年電商的發(fā)展可謂迅猛,因此我拿了一些電商平臺(tái)某產(chǎn)品品類的數(shù)據(jù)來進(jìn)行分析。本次文章主要是記錄本人對(duì)數(shù)據(jù)分析--電商行業(yè)所要掌握的基礎(chǔ)工具python的運(yùn)用與思維框架,無商業(yè)用途。(附上我在冬天的狀態(tài))

上分析框架:

數(shù)據(jù)表展示:

本項(xiàng)目數(shù)據(jù)共24列標(biāo)簽項(xiàng),共51101條數(shù)據(jù)進(jìn)行分析

一、讀取數(shù)據(jù)

import pandas as pddata = pd.read_csv('C:/Users/Desktop/dataset.csv',encoding='ISO-8859-1')data

二、數(shù)據(jù)處理(提取業(yè)務(wù)相關(guān)數(shù)據(jù))

①提取數(shù)據(jù)時(shí),處理與業(yè)務(wù)不符合邏輯的數(shù)據(jù),例如:售價(jià)為負(fù)

data[data.Sales<0]
沒有發(fā)現(xiàn)售價(jià)為負(fù)的數(shù)據(jù)
②判斷數(shù)據(jù)中是否存在不正常數(shù)據(jù),例如:發(fā)貨日期早于下單日期

# 1.發(fā)貨日期與訂單日期,轉(zhuǎn)成datetime形式data['ShipDate'] = pd.to_datetime(data['ShipDate'])data['OrderDate'] = pd.to_datetime(data['OrderDate'])# 2.發(fā)貨日期減去訂單日期,秒數(shù)data['interval']=(data.ShipDate-data.OrderDate).dt.total_seconds()data[data.interval<0]發(fā)現(xiàn)了四條存在發(fā)貨日期早于下單日期的不正常數(shù)據(jù)

③由于4條數(shù)據(jù)在全部數(shù)據(jù)的占比較小,況且也無從考證真正的時(shí)間段,因此選擇刪除

# 3.刪除異常數(shù)據(jù)# drop(index=刪除數(shù)據(jù)的index,inplace)data.drop(index=data[data.interval<0].index,inplace=True)data# 4.發(fā)貨時(shí)間-下單時(shí)間data['interval'] = data.ShipDate-data.OrderDatedata
刪除后剩下51097條數(shù)據(jù)

三、數(shù)據(jù)清洗

# 查看行列數(shù)量data.shape# 查看各列的非空數(shù)據(jù)量data.count()# NAN統(tǒng)計(jì)data.isna().sum()# 描述整體數(shù)據(jù)data.describe()# 數(shù)據(jù)信息data.info()由此可以發(fā)現(xiàn)ShipMode存在字符串缺失值,PostalCode存在缺失值,先放著稍后做處理

數(shù)據(jù)清洗的順序:1、先按唯一字段處理一邊重復(fù)值(本案的唯一字段是“RowID”,也就是訂單順序ID)2、處理異常值(補(bǔ))先做成空值,然后再填補(bǔ)空值;3、處理空值(補(bǔ));4、再處理一邊重復(fù)值,確保數(shù)據(jù)正常

①處理重復(fù)值

# 清洗RowID# 助理重復(fù)的個(gè)數(shù)data.RowID.unique().sizedata[data.RowID.duplicated()]# data.drop(index=data[data.RowID.duplicated()].index,inplace=True)# data發(fā)現(xiàn)有三個(gè)RowID重復(fù)的值,打開excel數(shù)據(jù)表格進(jìn)行核對(duì)

處理掉~

data.drop(index=data[data.RowID.duplicated()].index,inplace=True)data②處理Shipmode缺失值

# 處理Shipmode空值# 對(duì)付字符串的空值,彌補(bǔ),眾數(shù)data[data.ShipMode.isnull()]總共發(fā)現(xiàn)了11條因Shipmode存在空值的數(shù)據(jù),由于在數(shù)據(jù)表中Shipmode是以字符串的形式存在的

因此我們?cè)谔钊胱址畷r(shí)用Shipmode的眾數(shù)來進(jìn)行填入,利用mode()查看眾數(shù),然后填入空值欄中,結(jié)束后再次利用查空值代碼查看是否填補(bǔ)完

data.ShipMode.mode()data['ShipMode'].fillna(value=data.ShipMode.mode()[0],inplace=True)data# 檢查是否補(bǔ)完data[data.ShipMode.isnull()]當(dāng)顯示“0rows”,表示已經(jīng)填補(bǔ)完Shipmode里的空值

③處理PostalCode缺失值

查看PostalCode列中的數(shù)據(jù),發(fā)現(xiàn)是以數(shù)據(jù)形式存在的,這個(gè)具體要跟業(yè)務(wù)部門溝通缺失值的原因,在本案中無需分析,因此直接刪除,代碼如下:

# 郵編數(shù)據(jù)處理data.drop(columns=['PostalCode'],inplace=True)data④異常值處理,Discount數(shù)據(jù)處理

查看數(shù)據(jù)表中Discount異常值,代碼如下:

data[data.Discount>1]data[data.Discount<0]發(fā)現(xiàn)Discount中存在折扣>1的情況,而且有13條數(shù)據(jù)中的折扣存在這種情況,那么我們就要開始修正異常值數(shù)據(jù),代碼如下:

把折扣大于1的數(shù)據(jù),進(jìn)行修正data['Discount'] = data['Discount'].mask(data['Discount']>1,None)# 查看空值data[data.Discount.isnull()]# 平均折扣meanDisount = round(data[data['Discount'].notnull()].Discount.sum()/data[data['Discount'].notnull()].Discount.size,2)meanDisountdata['Discount'].fillna(value = meanDisount,inplace=True)data在這里,我們先將折扣>1的數(shù)值進(jìn)行空值替換,然后計(jì)算數(shù)據(jù)表中全部Discount的平均值,利用平均值對(duì)相應(yīng)空值進(jìn)行填補(bǔ),搞掂~~

⑤再次驗(yàn)證是否有重復(fù)值:

data[data.RowID.duplicated()]ok~~搞掂~到了這一步,已經(jīng)把全部數(shù)據(jù)清洗完畢,接下來就可以開展分析工作了!~

四、數(shù)據(jù)分析

按照我的慣例,我會(huì)先做數(shù)據(jù)規(guī)整,方便在之后的數(shù)據(jù)分析中單獨(dú)提取想要的字段數(shù)據(jù)即可

# 拆分成年,季度,月份data['Order-year'] = data['OrderDate'].dt.yeardata['Order-month'] = data['OrderDate'].dt.monthdata['quarter'] = data['OrderDate'].dt.to_period('Q')res=data[['OrderDate','Order-year','Order-month','quarter']].head()res1、每年銷售額增長(zhǎng)情況

銷售增長(zhǎng)率=(本年銷售額-上一年銷售額)/上一年銷售額*100%=本年銷售額/上一年銷售額-1

①計(jì)算每年銷售額

sales_year = round(data.groupby('Order-year')['Sales'].sum(),2)
sales_year

②銷售增長(zhǎng)率及百分比形式

sales_rate_12 = sales_year[2012]/sales_year[2011]-1sales_rate_13 = sales_year[2013]/sales_year[2012]-1sales_rate_14 = sales_year[2014]/sales_year[2013]-1sales_rate_12_label = "%.2f%%" % (sales_rate_12*100)sales_rate_13_label = "%.2f%%" % (sales_rate_13*100)sales_rate_14_label = "%.2f%%" % (sales_rate_14*100)print(sales_rate_12_label,sales_rate_13_label,sales_rate_14_label)③將sales_year、sales_rate、sales_rate_label形成dataframe

sales_rate = pd.DataFrame( {'sales_all':sales_year, 'sales_rate':[0,sales_rate_12,sales_rate_13,sales_rate_14], 'sales_rate_label':['0.00%',sales_rate_12_label,sales_rate_13_label,sales_rate_14_label]})sales_rate④繪制成圖形展現(xiàn)

import matplotlib.pyplot as pltimport matplotlib as mpl# 設(shè)置字體mpl.rcParams['font.sans-serif'] = 'SimHei'# 設(shè)置風(fēng)格plt.style.use('ggplot')# 銷售額y1 = sales_rate['sales_all'] # 增長(zhǎng)率y2 = sales_rate['sales_rate']x = [str(value) for value in sales_rate.index.tolist()]# 新建figure對(duì)象fig = plt.figure()# 新建子圖1fig,ax1 = plt.subplots(figsize=(20,12))# ax2與ax1共享x軸ax2 = ax1.twinx()ax1.bar(x,y1,color = 'blue')ax2.plot(x,y2,marker = '*',color = 'r')ax1.set_xlabel('年份')ax1.set_ylabel('銷售額')ax2.set_ylabel('增長(zhǎng)率')ax1.set_title('銷售額與增長(zhǎng)率')plt.savefig('電商銷售額與增長(zhǎng)率.png')plt.show()2、總銷售占比

sales_area = data.groupby('Market')['Sales'].sum()sales_area.plot(kind='pie',autopct="%1.1f%%",title='總銷售占比')plt.savefig('總銷售占比.png')plt.show()3、各地區(qū)每一年的銷售額

sales_area = data.groupby(['Market','Order-year'])['Sales'].sum()sales_area
輸出結(jié)果部分截圖
# 將分組后的多層索引設(shè)置成列數(shù)據(jù)sales_area = sales_area.reset_index(level=[0,1])sales_area
成為列數(shù)據(jù)后的部分截圖
# 使用數(shù)據(jù)透視表重新整理數(shù)據(jù)sales_area = pd.pivot_table(sales_area, index='Market', columns='Order-year', values='Sales')sales_area

將列數(shù)據(jù)轉(zhuǎn)換成為數(shù)據(jù)透視表,目的是整理數(shù)據(jù),使其用在下一步繪制成可視化圖形

# # 繪制圖形sales_area.plot(kind = 'bar',title = '2011年-2014年不同地區(qū)銷售額對(duì)比')plt.savefig('2011年-2014年不同地區(qū)銷售額對(duì)比.png')plt.show()4、不同類型產(chǎn)品在不同地區(qū)銷售額對(duì)比

category_sales_area = data.groupby(['Market','Category'])['Sales'].sum()category_sales_areacategory_sales_area = category_sales_area.reset_index(level=[0,1])category_sales_areacategory_sales_area = pd.pivot_table(category_sales_area, index='Market', columns='Category', values='Sales')category_sales_area.plot(kind = 'bar',title = '不同類型產(chǎn)品在不同地區(qū)銷售額對(duì)比',figsize=(10,8))plt.savefig('不同類型產(chǎn)品在不同地區(qū)銷售額對(duì)比.png')plt.show()5、銷售淡旺季分析

# 銷售淡旺季分析year_month = data.groupby(['Order-year','Order-month'])['Sales'].sum()year_month# 將分組后的多層索引設(shè)置成列數(shù)據(jù)year_month = year_month.reset_index(level=[0,1])year_month# 使用數(shù)據(jù)透視表重新整理數(shù)據(jù)year_month = pd.pivot_table(year_month, index='Order-month', columns='Order-year', values='Sales')# 繪制圖形year_month.plot(title='銷售淡旺季分析')plt.savefig('銷售淡旺季分析.png')plt.show()6、新增客戶

由于為了不干擾原數(shù)據(jù)表里面的數(shù)據(jù),我先將數(shù)據(jù)表進(jìn)行復(fù)制再進(jìn)行數(shù)據(jù)處理

# 1.復(fù)制data_customer = data.copy()# 2.處理數(shù)據(jù)data_customer = data_customer.drop_duplicates(subset = ['CustomerID'])data_customer在代碼撰寫上,我利用了drop_duplicates(subset = ['CustomerID'])來對(duì)customerID進(jìn)行去重,得到輸出結(jié)果如下:

剩下1590條客戶數(shù)據(jù)

接下來我對(duì)去重完畢的數(shù)據(jù)進(jìn)行分組整理、設(shè)置成列數(shù)據(jù)

# 3.分組new_customer = data_customer.groupby(by=['Order-year','Order-month']).size()new_customer# 將分組后的多層索引設(shè)置成列數(shù)據(jù)new_customer = new_customer.reset_index(level=[0,1])new_customer
部分列數(shù)據(jù)截圖
然后再利用可視化圖表來對(duì)數(shù)據(jù)進(jìn)行展示,代碼如下:

# 使用數(shù)據(jù)透視表重新整理數(shù)據(jù)new_customer = pd.pivot_table(new_customer, index='Order-month', columns='Order-year', values=0,fill_value=0)new_customernew_customer.plot(kind = 'bar',title = '新增客戶',figsize=(10,8))plt.savefig('新增客戶.png')plt.show()好啦~到了這里我對(duì)電商數(shù)據(jù)的分析步驟差不多尾聲了,其實(shí)在這龐大的數(shù)量里面還有很多可以挖掘的價(jià)值點(diǎn),但在這里就分享一些操作的方式以及代碼的運(yùn)用,在此,也做個(gè)總結(jié)方便小伙伴們?cè)谧鰯?shù)據(jù)分析能夠靈活運(yùn)用。

①sales_year = round(data.groupby('Order-year')['Sales'].sum(),2)sales_year#round(主值,2)這里的“2”表示主值得出的數(shù)值小數(shù)點(diǎn)保留2位#groupby('')['']為分析測(cè)算數(shù)值的聚合形式②year_month = pd.pivot_table(year_month, index='Order-month', columns='Order-year', values='Sales')# 使用數(shù)據(jù)透視表重新整理數(shù)據(jù) # 透視表與excel一致# # data,數(shù)據(jù)# # index,索引# # columns,列# # values,單元數(shù)據(jù)# # fill_value 補(bǔ)空數(shù)據(jù)③data_customer = data_customer.drop_duplicates(subset = ['CustomerID'])#去重?cái)?shù)據(jù)下一篇會(huì)重點(diǎn)向大家分享RFM模型的python語法,【PS:由于數(shù)據(jù)是進(jìn)行了脫敏處理的,所以存在多少商業(yè)價(jià)值取決于你關(guān)注哪個(gè)方面,再次重申:本文主要說明分析方法以及一些代碼展示,請(qǐng)勿利用于商業(yè)】最后也希望各位正往數(shù)據(jù)分析師發(fā)展的小伙伴們一路共勉,有空聊聊~

關(guān)鍵詞:數(shù)據(jù),分析,商行

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉