0

I have df

              subdomain search_engine search_term  
0                    vk.com          None        None  
1                    vk.com          None        None  
2              facebook.com          None        None  
3                    vk.com          None        None  
4                    vk.com          None        vkontakte  

I need to get 4 vk.com None vkontakte

I try

df[~df.search_term.str == r"None"]

But it returns TypeError: bad operand type for unary ~: 'StringMethods'

8
  • does df[df['search_term'].notnull()] work? Commented Jul 19, 2016 at 12:08
  • @EdChum None - it's string. And when I use your example it doesn't delete anything Commented Jul 19, 2016 at 12:10
  • How about df[df['search_term']!= "None"] Commented Jul 19, 2016 at 12:10
  • @EdChum it returns all dataframe Commented Jul 19, 2016 at 12:15
  • Then the cell element is not what you think it is can you show what df['search_term'].iloc[0] and type(df['search_term'].iloc[0]) returns Commented Jul 19, 2016 at 12:16

1 Answer 1

1

I think this should do it:

In[75]:df[df.search_term.str.strip()!='None']
Out[75]: 
  subdomain search_engine search_term
4    vk.com          None   vkontakte

or will this work:

df[~df.search_term.str.match('None')]
Sign up to request clarification or add additional context in comments.

6 Comments

I think I have some problem with my csv file. Nothing works
It didn't help. I have replaced this string to 0, but it didn't work too
try the solution with str.match.
Can you say, why did it happen? df[~df.search_term.str.match('None')] this not works but df = df[~df.search_term.str.match('None')] works?
what was the output when you ran the first statement without assigning it to df.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.