不同版本Level间权限打通率

import pandas as pd
import numpy as np
from datetime import date
today=date.today()

downpath='/Users/kangyongqing/Documents/kangyq/202207/王达/进阶P1L4至7无进阶P3对应权限名单/'
filename='20230918_145001.csv'
#从版本看板导出P1和P3的权限明细

word1=['L4','L5','L6','L7']

dt=pd.read_csv(downpath+filename,usecols=['老师id','老师姓名','教管','版本','级别合并'])
dt1=dt[(dt['版本']=='进阶版 P1')&(sum(dt['级别合并'].str.contains(word) for word in word1)>0)]
# dt1['级别']=dt1['级别合并'].mask(dt1.级别合并.str.contains('P1'),'P3')
#包含的统一替换为P3
dt1['级别']=dt1['级别合并'].str.replace('P1','P3')
print(dt1.head(1).T)
dt2=dt[(dt['版本']=='进阶版 P3')&(sum(dt['级别合并'].str.contains(word) for word in word1)>0)]
# print(dt2.head())


dt3=pd.merge(dt1,dt2,on='老师id',how='left')
print(dt3.head(1).T)
dt3['标签']=np.where(dt3['级别']==dt3['级别合并_y'],'权限相同','不一致')
print(dt3.head(1).T)

dt4=dt3.take([0,1,2,3,4,9,10],axis=1)
dt4['老师id']=dt3['老师id'].astype(np.int64).astype(str)

dt4['L4']=np.where((dt4['级别合并_x'].str.count('4')>dt4['级别合并_y'].str.count('4')),'缺','')
dt4['L5']=np.where((dt4['级别合并_x'].str.count('5')>dt4['级别合并_y'].str.count('5')),'缺','')
dt4['L6']=np.where((dt4['级别合并_x'].str.count('6')>dt4['级别合并_y'].str.count('6')),'缺','')
dt4['L7']=np.where((dt4['级别合并_x'].str.count('7')>dt4['级别合并_y'].str.count('7')),'缺','')
dt4[(dt4['L4']=='缺')|(dt4['L5']=='缺')|(dt4['L6']=='缺')|(dt4['L7']=='缺')].to_excel(downpath+'进阶P1L4至7权限'+str(today)+'.xlsx',index=False)

  1. np.where 制作标签
  2. 字符串计数

猜你喜欢

转载自blog.csdn.net/Darin2017/article/details/132984040
今日推荐