0

I am working with Pandas (python) on a dataset containing some fMRI results.

I am trying to drop rows when the value of a specific column is lower than a threshold I set. The thing is, I would also like to keep NAN values.

df = df[(dfr['in_mm3'] > 270) or (np.isnan(df['in_mm3']) == True)]

Obviously this doesn't work, but it is for you to better understand what I'm trying to achieve.

Any help would be appreciated.

Thanks.

Davide
  • 5
  • 5
  • Does this answer your question? [Keeping NaNs with pandas dataframe inequalities](https://stackoverflow.com/questions/33783027/keeping-nans-with-pandas-dataframe-inequalities) – ipj Aug 06 '20 at 09:06

2 Answers2

0

You are almost there. This should work:

import numpy as np
df = df[ np.logical_or(dfr['in_mm3'] > 270, np.isnan(df['in_mm3'])) ]
JacoSolari
  • 1,226
  • 14
  • 28
0
df = df[(dfr['in_mm3'] > 270) | (pd.isnan(df['in_mm3']))]

Here we are printing the values where pd.isnan(df['in_mm3']) is true and (dfr['in_mm3'] > 270) is satisfied

S.R Keshav
  • 1,965
  • 1
  • 11
  • 14