Reputation: 125
for i in range(0,len(donor_df)):
if donor_df['cand_nm'][i] == 'Obama, Barack':
donor_df['Party'] = 'Democrat'
else:
donor_df['Party'] = 'Republican'
donor_df
is a dataframe want to create a new column named 'party' but its not giving an output
Upvotes: 0
Views: 55
Reputation: 323276
You are looking for np.where
donor_df['Party']=np.where(donor_df['cand_nm'] == 'Obama, Barack','Democrat','Republican')
Upvotes: 1