Skip to content
Advertisement

Lambda function apply on dataframe DOES not contain str

I’m trying to add a condition .apply with a lambda function that pickups up a keyword but ignores values if they contain a specific word “total.”

My dataframe:

JavaScript

Here’s my code:

JavaScript

current col output:

JavaScript

Desired col output:

JavaScript

Question

What am I doing wrong? I have tried the ~ to make it a NOT but it’s still picking up rows and columns even if they contain the keyword “total.”

Advertisement

Answer

You can use regex like this:

JavaScript

Output:

JavaScript

OR

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement