0

I have a pandas dataframe column which value is nan and is a float:

df['column']

I want to add a logic there,if df['column'] equal float nan then do something,the problem is I have no idea how to check if it is float nan ,is there anyway like:

if df['column'] == 'nan':
   print('hi')
William
  • 3,724
  • 9
  • 43
  • 76
  • Your question is not clear, please be precise whether you want to check if the whole column is NaN, any value is NaN, or you want to apply a logic on rows with a NaN value and a different one on rows with values other than NaN – ADEL NAMANI Dec 13 '22 at 23:41

1 Answers1

0

Example

df = pd.DataFrame([[1, 2], [2, 3], [None, 4]], columns=['col1', 'col2'])

df

    col1    col2
0   1.0     2
1   2.0     3
2   NaN     4

Code

df.isna().sum() > 0

result:

col1     True
col2    False
dtype: bool

col1 has NaN and col2 has not NaN

Panda Kim
  • 6,246
  • 2
  • 12