0

Assume I have a dataframe df where the column A consists of 10 None and the rest is something else.

If I do the slicing df=df[df["A"]==None] I get a wrong result. I figured out that df["A"]==None returns False (even when the elements are None) but df["A"].values==None returns the correct.

How come? Shouldn't we be able to slice in the first way ?

Right leg
  • 16,080
  • 7
  • 48
  • 81
CutePoison
  • 4,679
  • 5
  • 28
  • 63

2 Answers2

1

You should use isna() method over the serie.

For your case:

df = df.loc[df['A'].isna()]
Ignacio Franco
  • 126
  • 1
  • 8
  • To explain the two different answers, the `df.isna()` and `df.isnull()` do the same thing -- they are aliases – moo Nov 27 '19 at 13:11
1

You can use as follows

df = df[df['A'].isnull()]
Omrum Cetin
  • 1,320
  • 13
  • 17