1

I have a DataFrame cMean. Its origin is some resampling of some data. It contains many NaN values and I wanted to get rid of them so I tried cMean[cMean.notnull()]. However, they still show up: enter image description here

Can you explain what is going on here? It seems cMean.notnull() works correct, as you can see here: enter image description here

mozway
  • 194,879
  • 13
  • 39
  • 75
principal-ideal-domain
  • 3,998
  • 8
  • 36
  • 73

1 Answers1

2

This doesn't work as cMean.notnull() gives you a 2D output, and you need a 1D Series to perform boolean indexing.

Use the specific column of interest:

out = cMean[cMean['population'].notnull()]

Or aggregate with any/all if you want to consider several columns:

out = cMean[cMean.notnull().any(axis=1)]

Note that you can also use dropna:

out = cMean.dropna(subset=['population'])
mozway
  • 194,879
  • 13
  • 39
  • 75