The code is supposed to do a conditional additional based on the values of gender, however the addition did not execute correctly
# Using apply on Male and Female
# Still didnt get the expected result to do addition and sub to the male and female
raw_data = {'Gender_demo': ["Male", "Female", "Male", "Female"],'Price': [100, 200, 300, 400]}
df = pd.DataFrame(raw_data, columns = ['Gender_demo','Price'])
df
def gensub (x, y, z):
if y == z:
return x + 75
else:
return x
df["Gender_Discount"]=df.Price.apply(gensub, y ="f.Gender_demo", z="Male")
df.head()
What I have
Gender_demo Price Gender_Discount
0 Male 100 100
1 Female 200 200
2 Male 300 300
3 Female 400 400
What I expect is an addition of 75 to the final Gender_Discount
variable if gender is male.