Reputation: 29
I have a dataframe with two columns, the first is filled with numbers (positive and negative) and the second is filled with strings (two types, 'Pos' and 'Neg'). I want a new third column to be added to the dataframe where the value of the numbers in the first column remains unchanged, but the plus or minus sign will be dependent on the second column only.
Here's my dataframe:
print(df_T)
num_1 W
0.788043 Neg
-1.745502 Neg
0.035905 Pos
1.306768 Pos
-0.034413 Neg
-1.228146 Pos
Here's my code:
if df_T['W'] == 'Neg':
df_T['eval'] = abs (df_T('num_1') * -1)
elif df_T['W'] == 'Pos':
df_T['eval'] = abs (df_T('num_1'))
else:
df_T ['eval'] = 0
print (df_T)
But something is apparently wrong since I get a warning from Python.
I would be very thankful if you could fix/explain me where I am wrong.
Upvotes: 0
Views: 38