Advertisement
DECROMAX

Pandas label column based on one condition

Feb 24th, 2024
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.17 KB | None | 0 0
  1. # Pandas label column based on one condition
  2.  
  3. df['new_column'] = np.where((df['target_column'] == 'condition'), 'Foo', 'Bar') # if `Foo` first val, else `Bar` second value
Tags: pandas numpy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement