I am trying to create a new column in my pandas Dataframe by passing multiple conditional statements through a lambda function.
My question is very similar to this one: Lambda including if...elif...else but the solution doesn't seem to work for my version of python (3.7).
Here's what I have so far:
With one condition, this works:
ops['repair_location'] = ops['depot_name'].apply(lambda x: 'Field' if x == 'Field else 'Depot')
But I want to add another condition. Using the solution to the linked question:
ops['repair_location'] = ops['depot_name'].apply(lambda x: 'Field' if x == 'Field' else (x == 'Unknown Location' 'Unknown Location' else 'Depot'))
This returns a syntax error pointing to the last else statement.
x == 'Unknown Location' 'Unknown Location'? In any case, you just have a bare-except, that isn't a complete conditional expression. You really should just use a full function definition, this lambda will quickly become unreadable