I would sugest to use Dataframe's apply as it is very simple and intuitive.
You can define a method you want to apply on the dataframe, you can choose either Lambda expression or explicit function for that. For example, here is a simple implementation with a function:
def func(row):
if row['PayFreq'] == 'Monthly':
return (row['Wages'] / 4) * 52
elif row['PayFreq'] == 'Bi-Weekly':
return (row['Wages'] / 2) * 52
else:
return row['Wages'] * 52
And in order to apply it on your dataframe (on the right axis):
df['NewWages'] = df.apply(func, axis=1)
The result:
Wages PayFreq NewWages
0 1013 Weekly 52676.0
1 5000 Monthly 65000.0
2 892 Weekly 46384.0
3 2320 Bi-Weekly 60320.0
4 1068 Weekly 55536.0
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…