考虑到分类列,需要将工资金额转换为年薪:
- 'M' - 每月
- 'Y' - 每年
- 'W' - 每周
- 'B' - 双周刊
df = pd.DataFrame({'Name':['A','B','C','D','E'],
'sal_amt':[4500,50000,2000,3000,5000],
'sal_md':['M','Y','W','B','M']})
df.head()
#defined a function for my problem...
def func(row):
if row['sal_md'] == 'M':
return (row['sal_amt']*12)
elif row['sal_md'] =='Y':
return row['sal_amt']
elif row['sal_md'] == 'H':
return (row['sal_amt']*8760)
elif row['sal_md'] == 'W':
return (row['sal_amt']*52)
elif row['sal_md'] == 'B':
return (row['sal_amt']*26)
elif row['sal_md'] == 'S':
return row['sal_amt']
elif row['sal_md'] == 'A':
return row['sal_amt']
df['sal_annual'] = df.apply(func,axis=1)