Given a koalas Dataframe:
df = ks.DataFrame({"high_risk": [0, 1, 0, 1, 1],
"medium_risk": [1, 0, 0, 0, 0]
})
Running a lambda function to get a new column based on the existing column values:
df = df.assign(risk=lambda x: "High" if x.high_risk else ("Medium" if x.medium_risk else "Low"))
df
Out[72]:
high_risk medium_risk risk
0 0 1 High
4 1 0 High
1 1 0 High
2 0 0 High
3 1 0 High
Expected return:
high_risk medium_risk risk
0 0 1 Medium
4 1 0 High
1 1 0 High
2 0 0 Low
3 1 0 High
Why does this assign "High" to each of the values. The intent is to operations on each row, is it looking at the whole column in the comparison?