I faced a curious doubt when i was executing a script using python.
I have a column called 'Status' which has value as either 'Success' or 'Failure'. I wanted to create two more column called 'SuccessCount' with value '1' if status is 'Success' and 'Failurecount' with value '1' if status is 'Failure'. I thought this was easy if I use lambda function and used below code
dffil["SuccessCount"] = dffil["Status"].apply(lambda x: 1 if x is 'Success' else 0)
dffil["FailureCount"] = dffil["Status"].apply(lambda x: 1 if x is 'Failure' else 0)
Now look at the output it generated
It gave SuccessCount as '0' even if the status was 'Success'. I got many values with such scenario. I checked for whitespace, removed it still the output didn't change.
Then I executed below code
dffil["SuccessCount"] = dffil["Status"].apply(lambda x: 1 if ((x=='Success') is True) else 0)
dffil["FailureCount"] = dffil["Status"].apply(lambda x: 1 if ((x=='Failure') is True) else 0)
This time it gave proper output, with a small change in lambda function, but logic was same
I am really curious to know what was the issue in first lambda funtion