(超實用)京東訂單數據分析案例-維度下鉆

1,數據介紹,字段了解

盡可能熟悉業務,多知道字段的含義,字段字段間的邏輯關系,后期數據分析思路才能更清晰,結果才能更準確

c7fc4fcab42e43178864ecefc0377264.png

2,訂單數據分析基本思路

維度下鉆

e065a34b8f004fc7a04cdfca786a5200.png

?

3,代碼實現全流程+思路

導包+繪圖報錯

import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns 
from scipy import stats
#加上了繪圖-全局使用中文+解決中文報錯的代碼
from matplotlib.ticker import FuncFormatter
plt.rcParams['font.sans-serif']=['Arial Unicode MS']import warnings
warnings.filterwarnings('ignore')

讀取數據,觀察表格特點(間隔符)

#雖然直接打開的文件顯得很亂,需要去發現還是以/t作為分隔符的
order = 'course_order_d.csv'
df = pd.read_csv(order,sep='\t', encoding="utf-8", dtype=str)

數據簡單查看

df.head()#查看數據是否為空+數據類型
df.info()

5c2ba15c46624187a849bd05edf5a4bd.png

數據清洗+預處理

#說明都是2020-5-25下的訂單
df['sale_ord_tm'].unique()#都是object,所以先轉化類型,再進行數據預處理
df['sale_qtty'] = df['sale_qtty'].astype('int')
df['sale_ord_valid_flag'] = df['sale_ord_valid_flag'].astype('int')
df['cancel_flag'] = df['cancel_flag'].astype('int')
df['self_ord_flag'] = df['self_ord_flag'].astype('int')df['before_prefr_unit_price'] = df['before_prefr_unit_price'].astype('float')
df['after_prefr_unit_price'] = df['after_prefr_unit_price'].astype('float')
df['user_actual_pay_amount'] = df['user_actual_pay_amount'].astype('float')
df['total_offer_amount'] = df['total_offer_amount'].astype('float')#pd.to_datetime()它可以用于將字符串或數字轉換為日期時間對象,還可以用于自動識別和調整日期時間。如果原始數據包含非標準的日期時間表示形式,則這個函數會更加有用
df.loc[:,'check_account_tm '] = pd.to_datetime(df.loc[:,'check_account_tm'])
df.loc[:,'sale_ord_tm'] = pd.to_datetime(df.loc[:,'sale_ord_tm'])
df.loc[:,'sale_ord_dt'] = pd.to_datetime(df.loc[:,'sale_ord_dt'])#個數/類型檢查
df.info()df.head()#異常處理
#優惠前冰箱的最低價格是288,低于這個價格為異常值
(df.loc[:,'before_prefr_unit_price']<288).sum()#確認優惠后價格,實際支付價格,總優惠金額 不是小于0的
(df.loc[:,'after_prefr_unit_price']<0).sum()(df.loc[:,'user_actual_pay_amount']<0).sum()(df.loc[:,'total_offer_amount']<0).sum()print('刪除異常值前',df.shape)
#去掉異常值
df=df[df['before_prefr_unit_price']>=288]
print('刪除異常值后:',df.shape)#確保每個訂單都是唯一的
#唯一屬性訂單ID-去重
df.drop_duplicates(subset=['sale_ord_id'],keep='first',inplace=True)
df.info()df.head()df.isnull().sum().sort_values(ascending=False)
#空值處理-補值
df.user_site_city_id=df.user_site_city_id.fillna('Not Given')
df.user_site_province_id=df.user_site_province_id.fillna('Not Given')#查看數值型字段的數據特征
df.describe()#再次檢查空值/類型
df.info()#+字段=邏輯處理
df['total_actual_pay']=df['sale_qtty']*df['after_prefr_unit_price']
df#檢查,空值,字段,類型
df.info()

宏觀分析

#取消訂單數量
order_cancel=df[df.cancel_flag==1]['sale_ord_id'].count()
order_cancel#訂單數量
order_num=df['sale_ord_id'].count()
order_numorder_cancel/order_num# 解決matplotlib中文亂碼matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['font.serif'] = ['SimHei']
matplotlib.rcParams['axes.unicode_minus'] = Falselabels=['取消','未取消']
X=[order_cancel,order_num-order_cancel]
fig=plt.figure()
plt.pie(X,labels=labels,autopct='%1.2f%%')
plt.title('訂單總數')
#取消未取消差不多3:7

a54619dfb2564a04a0bb79c9ce4a5df2.png

#求有效訂單中,支付,未支付
df2=df.copy()
#只包含有效訂單
df2=df2[(df2['sale_ord_valid_flag']==1)&(df2['cancel_flag']==0)&('before_prefr_unit_price'!=0)]#有效訂單數量
order_valid=df2['sale_ord_id'].count()
order_valid#支付訂單數量
order_payed=df2['sale_ord_id'][df2['user_actual_pay_amount']!=0].count()
order_payed#未支付訂單數量
order_unpay=df2['sale_ord_id'][df2['user_actual_pay_amount']==0].count()
order_unpayorder_unpay/order_payedlabels=['支付','未支付']
Y=[order_payed,order_unpay]
fig=plt.figure()
plt.pie(Y,labels=labels,autopct='%1.2f%%')
plt.title('有效訂單總數')

61babe40e74d4f08a62e06a74d31f11f.png

#訂單的價格分布
price_series=df2['after_prefr_unit_price']
price_seriesprice_series_num=price_series.count()
hist,bin_edges=np.histogram(price_series,bins=80)
hist_sum=np.cumsum(hist)
hist_per=hist_sum/price_series_numprint('hist:{}'.format(hist))
print('*'*100)
print('bin_edges:{}'.format(bin_edges))
print('*'*100)
print('hist_sum:{}'.format(hist_sum))hist_perbin_edges_plot=np.delete(bin_edges,0)plt.figure(figsize=(20,8),dpi=80)
plt.xlabel('訂單價格')
plt.ylabel('百分比')plt.style.use('ggplot')def to_percent(temp,position):return '%1.0f'%(100*temp)+'%'
plt.gca().yaxis.set_major_formatter(FuncFormatter(to_percent))
plt.plot(bin_edges_plot,hist_per,color='blue')

?

e4e0dee596244d7db934a2e81a6e8112.png

宏觀分析結束,到微觀分析啦

不同時間的有效訂單數

df3=df2.copy()
df3['order_time_hms']=df3['sale_ord_tm'].apply(lambda x:x.strftime('%H:00:00'))
df3pay_time_df=df3.groupby('order_time_hms')['sale_ord_id'].count()
pay_time_dfx = pay_time_df.index
y = pay_time_df.valuesplt.figure(figsize=(20,8),dpi=80)
plt.style.use('ggplot')
plt.xlabel('時間')
plt.ylabel("有效訂單量")
plt.xticks(range(len(x)), x, rotation=90)
rect = plt.bar(x, y, width=0.3, color=['#6699CC'])

62dc6fd7ec21483e964a6a03a9c9f7bd.png

0點訂單量最多,懷疑是不是單人下單多,下一步人均訂單數

import pandas as pd# 假設 df3 是你的原始 DataFrame
# 對 sale_ord_id 列按 order_time_hms 分組并計算計數
grouped = df3.groupby('order_time_hms')['sale_ord_id']# 獲取分組后的計數結果,如果是 Series,則轉換為 DataFrame
result_series = grouped.agg('count')
if isinstance(result_series, pd.Series):result_df = result_series.to_frame()
else:result_df = result_series# 重命名列
order_time_df = result_df.rename(columns={'sale_ord_id': 'order_num'})# 打印結果
print(order_time_df)
import pandas as pd# 假設 df3 是你的原始 DataFrame
# 對 user_log_acct 列按 order_time_hms 分組并計算每個組中唯一用戶的數量
grouped = df3.groupby('order_time_hms')['user_log_acct']# 獲取分組后的唯一用戶數量結果,如果是 Series,則轉換為 DataFrame
result_series = grouped.agg('nunique')
if isinstance(result_series, pd.Series):user_time_df = result_series.to_frame()
else:user_time_df = result_series# 重命名列
user_time_df = user_time_df.rename(columns={'user_log_acct': 'user_num'})# 打印結果
print(user_time_df)

739931ca751444a29f4ea9862b360895.png66ff0967bb234ef98404b0b8d450226d.png

order_num_per_user = order_time_df['order_num'] / user_time_df['user_num']x = order_num_per_user.index
y = order_num_per_user.valuesplt.figure(figsize=(20,8),dpi=80)
plt.style.use('ggplot')
plt.xlabel('時間')
plt.ylabel("人均有效訂單量")
plt.xticks(range(len(x)),x,rotation=90)
plt.plot(x, y)

2e30780085d94adcb6e778d61723b3b4.png

雖然0點訂單量還是最多,有些波動,繼續求客單價vs平均訂單價格

客單價(銷售額/顧客數)和平均訂單價格(銷售額/訂單數)

import pandas as pd# 假設 df3 是你的原始 DataFrame
# 對 total_actual_pay 列按 order_time_hms 分組并計算每個組的總和
grouped = df3.groupby('order_time_hms')['total_actual_pay']# 獲取分組后的總和結果
result_series = grouped.agg('sum')# 將結果轉換為 DataFrame
if isinstance(result_series, pd.Series):total_pay_time_df = result_series.to_frame()
else:total_pay_time_df = result_series# 重命名列
total_pay_time_df = total_pay_time_df.rename(columns={'total_actual_pay': 'total_pay'})# 打印結果
print(total_pay_time_df)

98ede200f73440cea3b1c99e03686f50.png

pay_per_user=total_pay_time_df['total_pay']/user_time_df['user_num']
pay_per_order=total_pay_time_df['total_pay']/order_time_df['order_num']x=pay_per_user.index
y=pay_per_user.values
y2=pay_per_order.valuesplt.figure(figsize=(20,8),dpi=80)
plt.style.use('ggplot')
plt.xlabel('時間')
plt.ylabel("價格")
plt.xticks(range(len(x)),x,rotation=90)plt.plot(x, y, color='red',linewidth=2.0,linestyle='--')
plt.plot(x, y2, color='blue',linewidth=3.0,linestyle='-.')
plt.legend(['客單價','平均訂單價'])

dd156136e22a49c696470af7064d4d60.png

觀察發現0點訂單量最多,隨后波動下滑,20點后開始平穩,是什么原因,繼續研究是不是跟訂單價格相關

df4=df3.copy()
df5=df3.copy()df4 = df4[df4['order_time_hms'] == '00:00:00']
df5 = df5[df5['order_time_hms'] == '20:00:00']def plot_acc_line(price_series, bin_num):len = price_series.count()hist, bin_edges = np.histogram(price_series, bins=bin_num) #生成直方圖函數hist_sum = np.cumsum(hist)hist_per = hist_sum / len * 100hist_per_plot = np.insert(hist_per, 0, 0)plt.figure(figsize=(20,8), dpi=80)plt.xlabel('訂單價格')plt.ylabel('百分比')plt.plot(bin_edges, hist_per_plot, color='blue')# 0時價格累積分布折線圖price_series_0 = df4['after_prefr_unit_price']
plot_acc_line(price_series_0, 100)# 20時價格累積分布折線圖,說明價格不是很大影響price_series_20 = df5['after_prefr_unit_price']
plot_acc_line(price_series_0, 100)

8b7a27a815bf4c54b8ae78138b25e7f1.png

似乎和價格關聯不大,那會不會和優惠相關呢,繼續分析

0時和其他時間的優惠占比

#驗證是不是和優惠相關
#0時的優惠訂單數
offer_order_0=df4['sale_ord_id'][df4['total_offer_amount']>0].count()
#0時訂單數
order_num_0=df4['sale_ord_id'].count()
#0時優惠訂單比
offer_order_per_0=offer_order_0/order_num_0
print('0時的優惠訂單數:{}, 0時的訂單數:{}, 優惠訂單比例:{}'.format(offer_order_0, order_num_0, offer_order_per_0))#全部優惠訂單數
offer_order_all=df3['sale_ord_id'][df3['total_offer_amount']>0].count()
#全部訂單數
order_all=df3['sale_ord_id'].count()
#其他時間優惠訂單數
offer_order_other=offer_order_all - offer_order_0
#其他時間訂單數
order_num_other=order_all-order_num_0
offer_order_per_other=offer_order_other/order_num_other
print('其他時間的優惠訂單數:{}, 其他時間的訂單數:{}, 其他時間優惠訂單比例:{}'.format(offer_order_other, order_num_other, offer_order_per_other))#0時,和其他時間的優惠訂單占比對比
plt.figure(figsize=(8,6),dpi=80)
N=2
index=('0時','除了0時之外')
data=(offer_order_per_0,offer_order_per_other)
width=0.35
plt.ylabel("優惠訂單占比")def to_percent(temp, position):return '%1.0f'%(100*temp) + '%'
plt.gca().yaxis.set_major_formatter(FuncFormatter(to_percent))p2 = plt.bar(index, data, width, color='#6699CC')

615cb3e2ac244d8d8634668f2c23008e.png

那會不會這個時間的某個優惠太多導致占比太大呢,繼續求0時平均優惠占比 vs 其他時間平均優惠占比

import pandas as pd# 假設 df3 是你的原始 DataFrame
# 對 user_log_acct 列按 order_time_hms 分組并計算每個組中唯一用戶的數量
grouped = df3.groupby('order_time_hms')['total_offer_amount']# 獲取分組后的唯一用戶數量結果,如果是 Series,則轉換為 DataFrame
result_series = grouped.agg('sum')
if isinstance(result_series, pd.Series):user_time_df = result_series.to_frame()
else:user_time_df = result_series# 重命名列
total_pay_time_df = user_time_df.rename(columns={'order_time_hms': 'total_offer_amount'})# 打印結果
print(total_pay_time_df)offer_amount_0=total_pay_time_df['total_offer_amount'][0]
offer_amount_other=total_pay_time_df[1:].apply(lambda x:x.sum())['total_offer_amount']offer_amount_0_avg=offer_amount_0/offer_order_0
offer_amount_other_avg=offer_amount_other/offer_order_other
print('0時平均優惠價格:{}, 其他時間平均優惠價格:{}'.format(offer_amount_0_avg, offer_amount_other_avg))#0時和其他時間的平均優惠價格對比:可視化
plt.figure(figsize=(8, 6), dpi=80)
N = 2
index = ('0時', '除了0時以外')values = (offer_amount_0_avg, offer_amount_other_avg)
width = 0.35plt.ylabel("平均優惠價格/元")p2 = plt.bar(index, values, width, color='#6699CC')

2dadfd952d4e473e8c10770debce6d52.png

確認0時訂單量大與優惠金額相關,接下來從地區維度拆分

df6=df2.copy()order_area_df=df6.groupby('user_site_province_id',as_index=False)['sale_ord_id'].agg('count')
order_area_dfimport pandas as pd# 假設 df3 是你的原始 DataFrame
# 對 user_log_acct 列按 order_time_hms 分組并計算每個組中唯一用戶的數量
grouped = df6.groupby('user_site_province_id',as_index=False)['sale_ord_id']# 獲取分組后的唯一用戶數量結果,如果是 Series,則轉換為 DataFrame
result_series = grouped.agg('count')
if isinstance(result_series, pd.Series):user_time_df = result_series.to_frame()
else:user_time_df = result_series# 重命名列
order_area_df = user_time_df.rename(columns={'sale_ord_id': 'order_num'})# 打印結果
print(order_area_df)order_area_df.drop([34],inplace=True)
order_area_df['province_id']=order_area_df['user_site_province_id'].astype('int')
order_area_dfcity = 'city_level.csv'
df_city = pd.read_csv(city,sep = ',', encoding="gbk", dtype=str)
df_city['province_id'] = df_city['province_id'].astype('int')
df_city#省份去重
df_city=df_city.drop_duplicates(subset=['province_id'],keep='first')
df_citydf_city=df_city[['province_id','dim_province_name']].sort_values(by='province_id',ascending=True).reset_index()
df_city.drop(['index'],axis=1,inplace=True)
df_cityorder_province_df=pd.merge(order_area_df,df_city,on='province_id').sort_values(by='order_num',ascending=False)
order_province_df

b9c901699e4b49fdad4b44730bded6a5.png

各個省份訂單量

#有效訂單量
plt.style.use('ggplot')x = order_province_df['dim_province_name']
y = order_province_df['order_num']plt.figure(figsize=(20,8),dpi=80)
plt.style.use('ggplot')
plt.xlabel('時間')
plt.ylabel("有效訂單量")
plt.xticks(range(len(x)), x, rotation=90)
rect = plt.bar(x, y, width=0.3, color=['#6699CC'])#有效訂單量-餅圖
plt.figure(figsize=(6,9)) 
labels = order_province_df['dim_province_name']plt.pie(order_province_df['order_num'], labels=labels,autopct='%1.2f%%') # autopct :控制餅圖內百分比設置, '%1.1f'指小數點前后位數(沒有用空格補齊);plt.axis('equal')
plt.show()

ebdc4d0fb0cb40b68305adcee0780833.png

4ba7625de44348f6829854c09b4cd28c.png

怕一個客訂單多,求各省份客單價對比

#各省份客單價對比cust_price_df = df6.groupby('user_site_province_id', as_index=False)['total_actual_pay'].agg({'total_pay':'sum'})
cust_price_df.columns = ['province_id','total_pay']
cust_price_df.drop([34], inplace=True)
cust_price_df['province_id'] = cust_price_df['province_id'].astype('int')
cust_price_df = pd.merge(cust_price_df, df_city, on='province_id').sort_values(by='total_pay', ascending=False)
cust_price_df['order_num'] = order_province_df['order_num']cust_df = df6.groupby('user_site_province_id', as_index=False)['user_log_acct'].agg({'user_num':'nunique'})
cust_df.columns = ['province_id','user_num']
cust_df.drop([34], inplace=True)
cust_df['province_id'] = cust_df['province_id'].astype('int')cust_price_df = pd.merge(cust_price_df, cust_df, on='province_id')
cust_price_df['cust_price'] = cust_price_df['total_pay'] / cust_price_df['user_num'] #計算客單價
cust_price_df = cust_price_df.sort_values(by='order_num', ascending=False)
cust_price_df = cust_price_df[:10]
cust_price_df = cust_price_df.sort_values(by='cust_price', ascending=False)cust_price_df

2ad9d93b52734828a4c64998e535bae8.png

plt.style.use('ggplot')x = cust_price_df['dim_province_name']
y = cust_price_df['cust_price']plt.figure(figsize=(20,8),dpi=80)
plt.style.use('ggplot')
plt.xlabel('時間')
plt.ylabel("客單價")
rect = plt.bar(x, y, width=0.3, color=['#6699CC'])

259170a97af44750b64b42ba31f1b26d.png

可能客單價大的訂單數小,可能客單價小的訂單數多,氣泡圖顯示

import matplotlib.pyplot as plt
import seaborn as snsplt.figure(figsize=(15, 10))x = cust_price_df['cust_price']
y = cust_price_df['order_num']# Calculate the minimum and maximum sizes based on your data
min_size = min(cust_price_df['cust_price']) * 3
max_size = max(cust_price_df['cust_price']) * 3# Use the calculated sizes for the scatterplot
ax = sns.scatterplot(x=x, y=y, hue=cust_price_df['dim_province_name'], palette=['#6699CC'], sizes=(min_size, max_size), size=x*3, legend=False)ax.set_xlabel("客單價", fontsize=12)
ax.set_ylabel("訂單數量", fontsize=12)province_list = [3, 5, 2, 1, 6, 7, 4, 9, 0, 11]# Adding text on top of the bubbles
for line in province_list:ax.text(x[line], y[line], cust_price_df['dim_province_name'][line], horizontalalignment='center', size='large', color='black', weight='semibold')plt.show()

fc4882042b9e4ede916b8b9dd8d09a65.png

知道上海雖然客單價高2600左右,但是訂單數量少600左右

廣東訂單數量多1800左右,客單價在2000左右

下一步,看頭部省份的四個品牌的滲透率

#不同品牌的產品單價
df7 = df2.copy()brand_sale_df=df7.groupby('brandname',as_index=False).agg({'total_actual_pay':'sum','sale_qtty':'sum'}).sort_values(by='total_actual_pay',ascending=False)
brand_sale_dfdf8 = df7.copy()df8 = df8[df8['user_site_province_id'] == '1'] # 省份取北京,數字是省份idbrand_sale_df_bj = df8.groupby('brandname', as_index=False).agg({'total_actual_pay':'sum', 'sale_qtty':'sum'}).sort_values(by='total_actual_pay', ascending=False)
brand_sale_df_bj = brand_sale_df_bj[(brand_sale_df_bj['brandname'] == '海爾(Haier)')|(brand_sale_df_bj['brandname'] == '容聲(Ronshen)')|(brand_sale_df_bj['brandname'] == '西門子(SIEMENS)')|(brand_sale_df_bj['brandname'] == '美的(Midea)')]
brand_sale_df_bjdf8=df7.copy()
df8=df8[df8['brandname']=='海爾(Haier)']brand_sale_df_haier=df8.groupby('user_site_province_id',as_index=False).agg({'total_actual_pay':'sum','sale_qtty':'sum'}).sort_values(by='total_actual_pay',ascending=False)
brand_sale_df_haier = brand_sale_df_haier[(brand_sale_df_haier['user_site_province_id'] == '1')|(brand_sale_df_haier['user_site_province_id'] == '2')|(brand_sale_df_haier['user_site_province_id'] == '12')|(brand_sale_df_haier['user_site_province_id'] == '22')|(brand_sale_df_haier['user_site_province_id'] == '19')]
brand_sale_df_haier['user_site_province_id'] = brand_sale_df_haier['user_site_province_id'].astype('int')
brand_sale_df_haier.columns = ['province_id','total_actual_pay', 'sale_qtty']
brand_sale_df_haier.sort_values(by='province_id')

11ffc2602ebf4ac1882197e9afb89eb4.png

cust_price_df

5c522757a89348f4b5866d3113aa31c1.png

order_num_df = cust_price_df[['province_id', 'order_num']][(cust_price_df['province_id'] == 1)|(cust_price_df['province_id'] == 12)|(cust_price_df['province_id'] == 19)|(cust_price_df['province_id'] == 2)|(cust_price_df['province_id'] == 22)]
order_num_df = order_num_df.sort_values(by='province_id')
order_num_df

4346d6ab5f1f45ec8721a8a49d0f4f95.png

滲透率

def province_shentou(df, brandname, cust_price_df):df = df[df['brandname'] == brandname]brand_sale_df = df.groupby('user_site_province_id', as_index=False).agg({'total_actual_pay':'sum', 'sale_qtty':'sum'}).sort_values(by='total_actual_pay', ascending=False)brand_sale_df = brand_sale_df[(brand_sale_df['user_site_province_id'] == '1')|(brand_sale_df['user_site_province_id'] == '2')|(brand_sale_df['user_site_province_id'] == '12')|(brand_sale_df['user_site_province_id'] == '22')|(brand_sale_df['user_site_province_id'] == '19')]brand_sale_df['user_site_province_id'] = brand_sale_df['user_site_province_id'].astype('int')brand_sale_df.columns = ['province_id','total_actual_pay', 'sale_qtty']brand_sale_df.sort_values(by='province_id')order_num = cust_price_df[['province_id', 'order_num']][(cust_price_df['province_id'] == 1)|(cust_price_df['province_id'] == 12)|(cust_price_df['province_id'] == 19)|(cust_price_df['province_id'] == 2)|(cust_price_df['province_id'] == 22)]order_num = order_num.sort_values(by='province_id')brand_sale_df = pd.merge(brand_sale_df, order_num_df, on='province_id')brand_sale_df['滲透率'] = brand_sale_df['sale_qtty'] / brand_sale_df['order_num']#銷售數量/訂單數量brand_sale_df = brand_sale_df.sort_values(by='province_id')return brand_sale_dfdf9 = df7.copy()brand_sale_df_rs = province_shentou(df9, '容聲(Ronshen)', cust_price_df)
brand_sale_df_siem = province_shentou(df9, '西門子(SIEMENS)', cust_price_df)
brand_sale_df_mi = province_shentou(df9, '美的(Midea)', cust_price_df)
brand_sale_df_haier = province_shentou(df9, '海爾(Haier)', cust_price_df)brand_sale_df_siem

14c821a5f37048d6a2c844e7c5c74eed.png

plt.style.use('ggplot')x = np.arange(5)y1 = brand_sale_df_siem['滲透率']
y2 = brand_sale_df_rs['滲透率']
y3 = brand_sale_df_haier['滲透率']
y4 = brand_sale_df_mi['滲透率']tick_label=['北京', '上海', '江蘇', '廣東', '四川']total_width, n = 0.8, 4
width = total_width / n
x = x - (total_width - width) / 2plt.figure(figsize=(20,8),dpi=80)
plt.style.use('ggplot')
plt.ylabel("滲透率")bar_width = 0.2
plt.bar(x, y1, width=bar_width, color=['red'])
plt.bar(x+width, y2, width=bar_width, color=['yellow'])
plt.bar(x+2*width, y3, width=bar_width, color=['green'])
plt.bar(x+3*width, y4, width=bar_width, color=['blue'])plt.xticks(x+bar_width/2, tick_label) # 顯示x坐標軸的標簽,即tick_label,調整位置,使其落在兩個直方圖中間位置

5b8f032e93d5416089aa7cae4da570a8.png

求各個品牌的客單價

plt.style.use('ggplot')brand_sale_df['單價'] = brand_sale_df['total_actual_pay'] / brand_sale_df['sale_qtty']
brand_sale_df = brand_sale_df.sort_values(by='單價', ascending=False)x = brand_sale_df['brandname']
y = brand_sale_df['單價']plt.figure(figsize=(20,8),dpi=80)
plt.style.use('ggplot')
plt.xlabel('品牌')
plt.ylabel("客單價")plt.xticks(range(len(x)), x, rotation=90)
rect = plt.bar(x, y, width=0.6, color=['#6699CC'])plt.show()

d1594315c9374e71a4c75755d1f66173.png

4,總結

1e76ea10d781479899b6be665b985688.png

(交個朋友/技術接單/ai辦公/性價比資源)

9fbb952aaa304c2dbcb1c743056ab15e.png

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/19821.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/19821.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/19821.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

華為telnet的兩種認證方式

華為telnet的兩種認證方式 實驗拓撲&#xff1a; 實驗要求&#xff1a; 1.采用普通密碼認證實現telnet 遠程登錄機房設備R3 2.采用AAA認證服務方式實現telnet 遠程登錄機房設備R3 實驗步驟&#xff1a; 1.完成基本配置&#xff08;設備接口配置IP&#xff0c;此步驟略過&#…

Facebook的隱私保護挑戰:用戶數據安全的新時代

在全球范圍內&#xff0c;Facebook已經成為了不可忽視的社交媒體巨頭&#xff0c;它連接著超過20億的活躍用戶。然而&#xff0c;隨著其影響力的不斷擴大&#xff0c;關于用戶隱私和數據安全的問題也愈加引人關注。本文將深入探討Facebook面臨的隱私保護挑戰&#xff0c;以及它…

一個程序員的牢獄生涯(47)學法

星期一 學法 二鋪不知道什么時候走到了我的身邊,向我說道,這是二鋪在我進來號子后主動過來和我說話。 我聽到二鋪這聲突兀的說話后,抬起頭。這時我才看到,除了二鋪,還有六子、棍子都圍在我的身邊,看著我。雖然六子和棍子依舊一副‘吊兒郎當’的樣子,但我從他們幾個的眼神…

解析前端開發中同源策略與配置代理

提示&#xff1a;文章寫完后&#xff0c;目錄可以自動生成&#xff0c;如何生成可參考右邊的幫助文檔 文章目錄 前言一、pandas是什么&#xff1f;二、使用步驟 1.引入庫2.讀入數據總結 前言 在前端開發中&#xff0c;跨域請求是一個常見的問題。同源策略限制了瀏覽器中一個頁面…

C++高手進階:Windows 模塊加載的藝術與策略

前文我們講到了怎么不依賴第三庫&#xff0c;搭建自己的測試框架 沒有看的讀者可以通過這個鏈接自行閱讀&#xff1a; &#x1f449;&#x1f449;&#x1f449; 自力更生&#xff1a;0依賴三方庫&#xff0c;手把手教你打造專屬C測試框架 作為項目開發來說&#xff0c;我們通常…

Leetcode:最長回文子串

題目鏈接&#xff1a;5. 最長回文子串 - 力扣&#xff08;LeetCode&#xff09; 普通版本&#xff08;暴力枚舉&#xff09; 解題關鍵&#xff1a; 1、記錄最長回文字串的長度和起始字符的下標 2、判斷回文字串的邏輯與整體邏輯分離 3、先確定尋找回文字串的邊界范圍后從兩邊向…

解析Java中1000個常用類:CharSequence類,你學會了嗎?

在 Java 編程中,字符串操作是最常見的任務之一。為了提供一種靈活且統一的方式來處理不同類型的字符序列,Java 引入了 CharSequence 接口。 通過實現 CharSequence 接口,各種字符序列類可以提供一致的 API,增強了代碼的靈活性和可擴展性。 本文將深入探討 CharSequence 接…

NBM 算法【python,算法,機器學習】

樸素貝葉斯法&#xff08;Naive Bayes model&#xff09;是基于貝葉斯定理與特征條件獨立假設的分類方法。 貝葉斯定理 P ( A ∣ B ) P ( B ∣ A ) ? P ( A ) P ( B ) P(A|B)\frac{P(B|A) * P(A)}{P(B)} P(A∣B)P(B)P(B∣A)?P(A)? 其中A表示分類&#xff0c;B表示屬性&…

Unity中的MVC框架

基本概念 MVC全名是Model View Controller 是模型(model)-視圖(view)-控制器(controller)的縮寫 是一種軟件設計規范&#xff0c;用一種業務邏輯、數據、界面顯示 分離的方法組織代碼 將業務邏輯聚集到一個部件里面&#xff0c;在改進和個性化定制界面及用戶交互的同時&#x…

【嵌入式硬件】DRV8874電機驅動

目錄 1 芯片介紹 1.1 特性簡介 1.2 引腳配置 1.3 最佳運行條件 2 詳細說明 2.1 PMODE配置控制模式 2.1.1 PH/EN 控制模式 2.1.2 PWM 控制模式 2.1.3 獨立半橋控制模式 2.2 電流感測和調節 2.2.1 IPROPI電流感測 2.2.2 IMODE電流調節 3.應用 3.1設計要求 3.2 設計…

AI換臉FaceFusion一鍵云部署指南

大家好&#xff0c;從我開始分享到現在&#xff0c;收到很多朋友的反饋說配置很低玩不了AI。本篇是一個云端部署AI項目的指南&#xff0c;幫助大家在云端進行AI項目的部署。我會從云平臺的選擇、代碼部署、保存鏡像幾個方面進行詳細的介紹。沒有代碼基礎的小白也不用擔心&#…

exe4j innosetup

exe4j:jdk: 打包時&#xff1a;需要的文件最好放到單獨的一個文件夾下&#xff0c;主機安裝32位jdk,exe4j用32位的。 附帶jre: jre用32位的&#xff08;jdk下的jre&#xff09;可使用X86,X64.用相對路徑。 只打64位時&#xff0c;需要選擇32-bit or 64-bit (generate 64…

樂觀鎖 or 悲觀鎖 你怎么選?

你有沒有聽過這樣一句話&#xff1a;悲觀者正確&#xff0c;樂觀者成功?。那么今天我來分享下什么是樂觀鎖?和悲觀鎖。 樂觀鎖和悲觀鎖有什么區別&#xff0c;它們什么場景會用 樂觀鎖 樂觀鎖基于這樣的假設&#xff1a;多個事務在同一時間對同一數據對象進行操作的可能性很…

fps游戲中如何將矩陣轉換為二維屏幕上的矩形坐標

fps游戲中如何將矩陣轉換為二維屏幕上的矩形坐標 matrix[4][4]: 4x4 矩陣&#xff0c;通常用于3D變換&#xff08;如模型視圖投影矩陣&#xff09;。 float* location: 一個指向位置坐標的指針&#xff0c;表示要轉換的3D位置。 int Window_w, int Window_h: 窗口的寬度和高…

工廠模式詳情

一.介紹工廠模式的用途與特點 工廠方法模式是一種創建型設計模式&#xff0c; 其在父類中提供一個創建對象的方法&#xff0c; 允許子類決定實例化對象的類型。定義工廠方法模式(Fatory Method Pattern)是指定義一個創建對象的接口&#xff0c;但讓實現這個接口的類來決定實例…

Python導出Jira列表

import requests import urllib3 urllib3.disable_warnings() from jira import JIRA import pandas as pd def login_jira(username,password):jira JIRA("https://jira.cn/",basic_auth(username,password))#projectsjira.project(id13)# jqlproject"云鏈-…

基于強化學習的控制率參數自主尋優

1.介紹 針對控制建模與設計場景中控制參數難以確定的普遍問題&#xff0c;提出了一種基于強化學習的控制律參數自主優化解決方案。該方案以客戶設計的控制律模型為基礎&#xff0c;根據自定義的控制性能指標&#xff0c;自主搜索并確定最優的、可狀態依賴的控制參數組合。 可…

unity打包的WebGL部署到IIS問題

部署之后會出錯&#xff0c;我遇到的有以下幾種&#xff1b; 進度條卡住不動 明明已經部署到了IIS上&#xff0c;為什么瀏覽網頁的時候還是過不去或者直接報錯。 進度條卡住不動的問題其實就是wasm和data的錯誤。 此時在瀏覽器上按F12進入開發者模式查看錯誤&#xff08;下圖…

前端知識點雜記

本文章用于記錄前端學習中遇到的瑣碎問題及解決方法&#xff0c;歡迎大家一起學習補充~ 前端如何獲取UUID發送至后端&#xff1f; 1. 命令行下載uuid庫 npm install uuid 2. 工程導入uuid庫 import { v4 as uuidv4 } from "uuid"; 3. 使用方法生成uuid實例 co…

付費工具邏輯

1.付費推廣目的&#xff1a; 傳播信息心理暗示&#xff1b;擴大銷售&#xff0c;指導消費&#xff1b;樹立形象&#xff0c;塑道品牌&#xff1b; 2.付費和免費廣告&#xff1a; 付費主要為了增加曝光&#xff1b;免費廣告一般比付費廣告轉化率高&#xff1b; 3.平臺廣告交…