dict_1=dict(zip(qhcs_nc['姓名'],qhcs_nc['是否切换区域']))
jsmb1['是否切换城市']=jsmb1['员工\n编号'].map(dict_1)
dict1=pd.read_excel(data1,sheet_name="职级").set_index('职级')['对应等级'].to_dict()
raw_data['对应等级']=raw_data['职级'].map(dict1)
(if 函数)
传输列表只能是数值列表{且是原始列表}
(必须结合set_xticks使用,否则会丢失第一个值)
def zuhe(i, j, x, y, z, w):
fig, ax1 = plt.subplots(figsize=(14, 8))
ax2 = ax1.twinx()
x1 = np.arange(len(x))
bar1 = ax1.bar(x1, y, color='orange', label="人数", width=0.3)
bar2 = ax1.bar(x1+0.3, z, color='gray', label="平均产能", width=0.3)
pl1 = ax2.plot(x1+0.15, w, color='yellow', label="成本率")
title = "%s人员产能及薪酬-%s" % (j, i)
ax1.set_title(title)
ax1.bar_label(bar1)
ax1.bar_label(bar2, fmt='%d')
ax1.set_xticks(x1+0.15) # x轴标签的位置右移0.15(没有set_xticklabels时会以此值为轴标签显示)
ax1.set_xticklabels(x.values) # x轴标签的值
ax1.legend(loc='best', frameon=False)
ax2.legend(loc='right', frameon=False)
plt.savefig("%s.png" % title, format="png")
for i in yewu:
for j in dengji:
x = raw_data[(raw_data['业务'] == "%s" % i) & (
raw_data['对应等级'] == "%s" % j)]['职级']
y = raw_data[(raw_data['业务'] == "%s" % i) & (
raw_data['对应等级'] == "%s" % j)]['人数']
z = raw_data[(raw_data['业务'] == "%s" % i) & (
raw_data['对应等级'] == "%s" % j)]['平均产能']
w = raw_data[(raw_data['业务'] == "%s" % i) & (
raw_data['对应等级'] == "%s" % j)]['成本率(元效)']
# zhuzhuang(i, j, x, y, z)
zuhe(i, j, x, y, z, w)
# 缺少的城市法1(复杂度较高)
pro_city2=tai1[tai1.astype(str).apply(lambda x:x.pro_city2 not in x.pro_city1,axis=1)]['pro_city1'].unique
da2=tai1[tai1.astype(str).apply(lambda x:x.二网经销商市 not in x.城市,axis=1)]
da2.drop_duplicates(['二网经销商市'])['二网经销商市']
da2.drop_duplicates(['二网经销商省'])['二网经销商省']
## 缺少的城市法2
list_pro=[]
for i in pro1:
if i not in list(pro2):
list_pro.append(i)
len(list_pro)
## 缺少的城市法3
tai["判断列"]=np.where(tai['二网经销商市'].isin(list(data1['城市'])),1,0)
len(set(tai[tai["判断列"]==0]['二网经销商市']))
# contains多个字符串包含,用|表示,且在一个引号内
jsmb['是否虚拟']=np.where(jsmb['岗位'].str.contains('常规|虚拟'),"是","否")
jsmb['是否虚拟'].value_counts()
# 追加写入csv
for i in range(1,7):
lujing=r"D:\ZXL工作文件\Jupyter\补录表\存量%s收入.xlsx" %i
buchong=pd.read_excel(lujing)
buchong.to_csv('da1.csv',encoding='GBK',index=False,mode="a",header=False)
yytz_cp_pivot=yytz_cp.pivot_table(values=['融资金额付款审批','融资金额*期限','融资额*期限*X','融资额*期限*利率','产品'],
index=["新车or二手车","渠道描述区域",'万元系数1'],
columns="月份",
aggfunc={'融资金额付款审批':"sum",'融资金额*期限':"sum",'融资额*期限*X':"sum",'融资额*期限*利率':"sum",'产品':"count"},
margins=True)
yytz_cp_pivot.query('新车or二手车=="二手车"')
yytz_cp_pivot.query('新车or二手车=="二手车" and 渠道描述区域=="%s"'%quyu)
yytz_cp_pivot[('产品',4)]
yytz_cp_pivot['单量父级占比4']=round(yytz_cp_pivot[('产品',4)].sum(level=["新车or二手车","渠道描述区域",'万元系数1'],axis=0)/yytz_cp_pivot[('产品',4)].sum(level=["新车or二手车","渠道描述区域"],axis=0),4)
yytz_cp_pivot['单量父级占比5']=round(yytz_cp_pivot[('产品',5)].sum(level=["新车or二手车","渠道描述区域",'万元系数1'],axis=0)/yytz_cp_pivot[('产品',5)].sum(level=["新车or二手车","渠道描述区域"],axis=0),4)
yytz_cp_pivot['单量父级占比6']=round(yytz_cp_pivot[('产品',6)].sum(level=["新车or二手车","渠道描述区域",'万元系数1'],axis=0)/yytz_cp_pivot[('产品',6)].sum(level=["新车or二手车","渠道描述区域"],axis=0),4)
yytz1=yytz_cp.pivot_table(values=['产品'],
index=["新车or二手车","渠道描述区域",'万元系数1'],
columns="月份",
aggfunc={'产品':"count"})
yytz1['分子']=yytz1['产品'].sum(level=["新车or二手车","渠道描述区域",'万元系数1'],axis=0)
yytz1['分母']=yytz1['产品'].sum(level=["新车or二手车","渠道描述区域"],axis=0)
yytz1['占比']=yytz1['分子']/yytz1['分母']