Pandas Request No Values

I have a dataframe with columns of different types, and I need to use pandas.query to filter the columns.

Columns can include missing values: NaN , None and NaT , and I need to display rows containing such values. Is there a way to do this in an expression passed to pandas.query ? I know that this can be done using different methods, but I need to know if this is doable through query

For boolean columns, I was able to use a workaround by specifying:

 df.query('col not in (True, False)') 

but this will not work for other column types. Any help is appreciated, including workarounds.

+5
source share
1 answer

NaN not equal to itself, so you can simply check to see if a column is equal to filter it. This seems to work for None too, although I'm not sure why at some point during the evaluation it can be added to NaN .

  df.query('col == col') 

In datetime, this works, but feels pretty hacked, maybe the best way.

 df.query('col not in [@pd.NaT]') 
+4
source

All Articles