Answers for "create new column with mask pandas"

0

create new column with mask pandas

mask0 = (df['condition'] == 1)
mask1 = (df['condition'] == 0)

df.loc[mask0, 'newColumn'] = df.loc[mask0, 'otherColumn1']
df.loc[mask1, 'newColumn'] = df.loc[mask1, 'otherColumn2']
Posted by: Guest on September-12-2021

Code answers related to "create new column with mask pandas"

Python Answers by Framework

Browse Popular Code Answers by Language