0

I would like to set a condition in the dataframe for every row that says if value of columnA = 1 then df['outcome'] is 'Yes' and if not then 'No'

So something like this: df.loc[df['columnA']=1,'outcome']='Yes' else 'No'

2
  • 2
    df['outcome']=df['columnA'].eq(1).map({True:'Yes',False:'No'}) Commented Aug 4, 2021 at 14:00
  • also you can use loc 2 times if you wish Commented Aug 4, 2021 at 14:08

1 Answer 1

1

You can simply use np.where

import numpy as np
df['outcome'] = np.where(df['columnA'] == 1, 'Yes', 'No')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.