Reputation: 1
I need help I create this dataframe:
And i need to create a new column with this function:
def pgto(x, num):
if x == "(i)":
return num
elif x == "(ii)":
return 750000.00
elif x == "(iii)":
return num * 0.7
else:
return 3000000.00
then i aplicate a multiple loop for:
for x in df_final["Tipo"]:
for num in df_final["Valor_float"]:
df_final["Pgto"] = pgto(x, num)
But the result was it:
What i should do?
Upvotes: 0
Views: 60
Reputation: 4482
You are not correctly looping over rows, I'd suggest the following:
for idx, row in df_final.iterrows(): #Proper way to loop over rows
# with the idx value (~row number), you can store the output value of your function
df_final.loc[idx, "Pgto"] = pgto(row['Tipo'], row['Valor_float'])
Upvotes: 1