df:
score_difference DNB selection selection_match
0 1.040000 0.65 DNB No Match
1 0.894543 0.65 DNB No Match
2 2.120546 2.11 DNB No Match
3 0.672945 0.65 DNB No Match
4 1.578659 0.96 DNB No Match
5 2.746971 2.72 DNB No Match
I am trying to write a function if selection_match == 'No Match' then DNB = score_difference + 0.02
def selection_mod_dnb(row):
if row["selection_match"] == "No Match" and row['selection'] == "DNB":
return 0.02 + float(row['score_difference'])
else:
return row['DNB']
df['DNB'] = df.apply(selection_mod_dnb, axis=1)
However, I return the same df without any modifications
df:
score_difference DNB selection selection_match
0 1.040000 0.65 DNB No Match
1 0.894543 0.65 DNB No Match
2 2.120546 2.11 DNB No Match
3 0.672945 0.65 DNB No Match
4 1.578659 0.96 DNB No Match
5 2.746971 2.72 DNB No Match
while it should return
score_difference DNB selection selection_match
0 1.040000 1.060000 DNB No Match
1 0.894543 0.914543 DNB No Match
2 2.120546 2.140546 DNB No Match
3 0.672945 0.692945 DNB No Match
4 1.578659 1.598659 DNB No Match
5 2.746971 2.766971 DNB No Match
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
predicted_score_differencecolumn in your dataframe