2

I am trying to remove all rows in a Panda dataset that contain the symbol "+" anywhere in the row. So ideally this:

 Keyword +John Mary+Jim David 

would become

 Keyword David 

I've tried doing something like this in my code but it doesn't seem to be working.

excluded = ('+') removal2 = removal[~removal['Keyword'].isin(excluded)] 

The problem is that sometimes the + is contained within a word, at the beginning of a word, or at the end. Any ideas how to help? Do I need to use an index function? Thank you!

1 Answer 1

3

Use the vectorised str method contains and pass the '+' identifier, negate the boolean condition by using ~:

In [29]: df[~df.Keyword.str.contains('\+')] Out[29]: Keyword 2 David 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.