受注処理
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import os
import warnings
warnings.filterwarnings('ignore')
データを読む
path = r'H:\ \ \ \クジラのデータ分析プロジェクト\Tmall注文/tmallの総合分析_order_report.csv'
df = pd.read_csv(path,engine = 'python',encoding = 'utf')
df.head(1)
df.tail(1)
加工データ
標準化された分野名
df.columns
df.info()
リピート金額
df.duplicated().sum()
欠測値
df.isnull().sum()
# 注文の支払時期 2,923件の欠落があるが、これは正常な現象であり、これらの単位は支払済みであり、処理する必要がないことを示している。
注文転換率 - ファネルチャート
各セグメントのデータを計算
- 以下のデータが取得されます。
[注文総数', '28010']、
['全額支払いの注文数', '18441']. - バイヤーが実際に支払った金額:合計金額-払い戻し金額。金額は0です。
- 払い戻し金額:支払い後に要求された払い戻し金額。お支払いがない場合、返金額は0になります。
受注総数
dict_convs = dict()
key = '受注総額
dict_convs[key] = len(df)
len(df)
受注件数
key = '有料注文数
# 支払い時間が空でなければ、支払いが完了したことを意味する。
df_payed = df[df['注文支払時期].notnull()]
dict_convs[key] = len(df_payed)
len(df_payed)
受注件数
key = '入荷数
# バイヤーが実際に支払った金額:総額-返金額
# バイヤーが実際に支払った金額はゼロではない。
df_trans = df_payed[df_payed['バイヤーの実際の支払額] != 0]
dict_convs[key] = len(df_trans)
len(df_trans)
完済注文数
key = '全額支払の注文数
# 支払い済みの注文のうち、払い戻し額は0である。
df_trans_full = df_payed[df_payed['返金額] == 0]
dict_convs[key] = len(df_trans_full)
len(df_trans_full)
# コンバージョンデータを見る
dict_convs
転換率-現在
df_convs = pd.Series(dict_convs,name = '受注件数').to_frame()
df_convs
全体の転換率
# 全体のコンバージョン率、各リンクを注文の総数で割って足す
name = '全体のコンバージョン率
total_convs = df_convs['受注件数]/df_convs.loc['総受注件数','受注件数'']*100
df_convs[name] = total_convs.apply(lambda x : round(x,0)) #round() メソッドは浮動小数点数の丸め値を返す。
df_convs
from pyecharts.charts import Funnel
from pyecharts import options as opts
funnel = Funnel().add(
series_name = name,
data_pair = [ list(z) for z in zip(df_convs.index,df_convs[name]) ],
is_selected = True,
label_opts = opts.LabelOpts(position = 'inside')
)
funnel.set_series_opts(tooltip_opts = opts.TooltipOpts(formatter = '{a}<br/>{b}:{c}%'))
funnel.set_global_opts( title_opts = opts.TitleOpts(title = name),
# tooltip_opts = opts.TooltipOpts(formatter = '{a}<br\>{b}:{c}%'),
)
funnel.render_notebook()
シングルリンク転換率
# 単一リンクのコンバージョン率、前のリンクを除く各リンクを追加する。
name = 'シングルリンクのコンバージョン率
single_convs = df_convs['受注件数].shift()
df_convs[name] = single_convs.fillna(df_convs.loc['総受注件数','受注件数''])
# df_convs[name] = (df_convs['受注件数]/df_convs[name]*100).apply(lambda x : round(x,0))
df_convs[name] = round((df_convs['受注件数]/df_convs[name]*100),0)
df_convs
name = 'シングルリンクのコンバージョン率
funnel = Funnel().add(
series_name = name,
data_pair = [ list(z) for z in zip(df_convs.index,df_convs[name]) ],
is_selected = True,
label_opts = opts.LabelOpts(position = 'inside')
)
funnel.set_series_opts(tooltip_opts = opts.TooltipOpts(formatter = '{a}<br/>{b}:{c}%'))
funnel.set_global_opts( title_opts = opts.TitleOpts(title = name),
# tooltip_opts = opts.TooltipOpts(formatter = '{a}<br\>{b}:{c}%'),
)
funnel.render_notebook()
全体の受注動向
# 決済別受注状況
df_trans['注文作成時間] = df_trans['注文作成時間].astype('datetime64')
df_trans=df_trans.set_index('注文作成時間')
df_trans.head(1)
#xLable表示されない場合:plt描画がフォントを見つけることができない場合は、次のように、プログラムの2行を追加する必要がある:
plt.rcParams['font.sans-serif']=['SimHei'] #ラベルを表示する
plt.rcParams['axes.unicode_minus']=False
se_trans_month = df_trans.resample('D')['注文数].count()
se_trans_month.plot()
se_trans_month.name
from pyecharts.charts import Line
name = '受注件数
(
Line()
.add_xaxis(xaxis_data = list(se_trans_month.index.day.map(str)))
.add_yaxis(
series_name= name,
y_axis= se_trans_month,
)
.set_global_opts(
yaxis_opts = opts.AxisOpts(
splitline_opts = opts.SplitLineOpts(is_show = True)
)
)
.render_notebook()
)
結論
2月前半、ほとんどの企業が仕事を再開していない、宅配便のシャットダウン、注文を出荷することはできません。
月の後半は、仕事に戻って企業の数が徐々に増加し、注文の数が増加し始めました。
#平均受注価格
df_trans['バイヤーの実際の支払額].mean()
地域別売上高分布図
#xLable表示されない場合:plt描画がフォントを見つけることができない場合は、次のように、プログラムの2行を追加する必要がある:
plt.rcParams['font.sans-serif']=['SimHei'] #ラベルを表示する
plt.rcParams['axes.unicode_minus']=False
se_trans_map = df_trans.groupby('受取住所')['受取住所の].count().sort_values(ascending = False)
plt.figure(dpi = 100)
se_trans_map.plot(kind = 'bar')
# len(se_trans_map)
df.columns
# '注文番号」、「合計金額」、「購入者が実際に支払った金額」、「配送先住所」、「注文作成時間」、「注文支払時間」、「返金金額
# 以下の地理分布図により使用されている省名の一貫性を保つため、自治区を扱う機能を定義する。
def strip_region(iterable):
result = []
for i in iterable:
if i.endswith('自治区):
if i == '内モンゴル自治区の:
i = i[:3]
result.append(i)
else:
result.append(i[:2])
else:
result.append(i)
return result
# 自治区の取り扱い,
se_trans_map.index = strip_region(se_trans_map.index)
# 最後の「県」を削除する。
se_trans_map.index = se_trans_map.index.str.strip('
import pyecharts.options as opts
from pyecharts.charts import Map
# 地理的分布図を表示する
name = '受注件数
(
Map()
.add(
series_name = name,
data_pair= [list(i) for i in se_trans_map.items()])
.set_global_opts(visualmap_opts=opts.VisualMapOpts(
max_=max(se_trans_map)*0.6
)
)
.render_notebook()
)





