Conditional Logic
General Info
Useful Snippets

10.0.9 CASE WHEN logic - Option 1 - pandas .loc

Example:

# Create a new column where condition is true (new column will be 'NaN' where it's not true)
DF.loc[DF['B'] == 'b', 'new_column_name'] = 'value_if_true'

# Create a second statement where where condition is NOT true to update all the other values 
DF.loc[DF['B'] != 'b', 'new_column_name'] = 'value_if_false'

Discussion:

With this method, you don't need to set the processed column equal to the new column.