Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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'
df['outcome']
So something like this: df.loc[df['columnA']=1,'outcome']='Yes' else 'No'
df.loc[df['columnA']=1,'outcome']='Yes' else 'No'
df['outcome']=df['columnA'].eq(1).map({True:'Yes',False:'No'})
You can simply use np.where
import numpy as np df['outcome'] = np.where(df['columnA'] == 1, 'Yes', 'No')
Add a comment
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
df['outcome']=df['columnA'].eq(1).map({True:'Yes',False:'No'})