0

I have a column called "marital_status" which contains 6 different classes. I want to transform them into 1 and 0 based on a condition.

Like if marital_status is in ["Married-civilian spouse present" or "Married-spouse absent" or "Married-A F spouse present"] replace with 1 else 0 for rest of three(out of 6).

I have tried below code but it replace all values in column with 0 and nothing with 1.

df_filtered['is_married'] = df_filtered['marital_status'].apply(lambda status: 1 if (status == "Married-civilian spouse present" or status == "Married-spouse absent" or status=="Married-A F spouse present") else 0 )

Pranav
  • 1
  • 1

0 Answers0