处理邮箱后缀

import pandas as pd

filepath='/Users/kangyongqing/Documents/kangyq/202206/季度评级月数据支持/2023年薪改测算/邮件推送/有效邮箱确认/'
file='有效邮箱确认.xlsx'

df=pd.read_excel(filepath+file,sheet_name=0,usecols=[0,1,2,3])
print(df.head())
print(type(df))
df[['账号','类型']]=df['email'].str.split("@",expand=True)
df.drop(['账号'],axis=1,inplace=True)
print(df.head())

pvt=pd.pivot_table(df,index='类型',aggfunc='count',values='教师id').sort_values(by='教师id',ascending=False).reset_index()
pvt['zhanbi']=pvt['教师id']/pvt['教师id'].sum()
pvt['zhanbi']=pvt['zhanbi'].round(4).apply(lambda x:format(x,'.2%')) #保留四位小数并百分比展示
print(pvt)



excel分列;

透视表;

百分比展示;

猜你喜欢

转载自blog.csdn.net/Darin2017/article/details/132860760