0

How do you filter empty cells in a column in a form of

blank = '' df = df[(df['Remarks']== blank)]

please give me suggestion in the given form because i want to add multiple conditions using & or |. I tried this and the output was an error.

jpp
  • 159,742
  • 34
  • 281
  • 339
samuelcs
  • 33
  • 4
  • 2
    What is your error? Please provide full traceback and a **[mcve]**. – jpp Jul 06 '18 at 11:38
  • it didnt show any error. It just didnt filter the blank cells. – samuelcs Jul 06 '18 at 11:50
  • 2
    Please don't include links / images. These aren't helpful. Instead, see **[How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples)**. – jpp Jul 06 '18 at 11:54

2 Answers2

0

I dont know what type of data you have, as you havent posted anything here. But may be you need to convert your columns to string using str and then do comparision try this

blank = ''
df = df[(df['Remarks'].str == blank)]
user96564
  • 1,578
  • 5
  • 24
  • 42
0

It could be that your columns aren't actually blank, but are nan/null.

Try the following;

df = df[df['Remarks'].isnull()]

I've removed the parenthesis from your example because you don't need to enclose a single conditional, only when you are passing multiple conditions, as such;

df = df[(df['Remarks']isnull()) & (df['Remarks'] == 'Some Value')]
Nordle
  • 2,915
  • 3
  • 16
  • 34
  • the .isnull() is working. However, what if i want to say it is equal to not null? – samuelcs Jul 09 '18 at 03:39
  • solved! just use .notnull() series – samuelcs Jul 09 '18 at 03:50
  • Exactly like so. Also if you do need to check an if statement is False, you can insert a '~' before the statement like so; `df = df[(df['Remarks']isnull()) & (~df['Remarks'] == 'Some Value')]` This checks that the value is null, and that the value does NOT equal 'Some Value' – Nordle Jul 09 '18 at 10:00