2

Is there a way to check if a particular value in a particular row and column of a dataframe is nan?

I tried np.isnan(df.loc[no,'LatinDesc']) where no is the row no but I am getting the following error:

ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

user42967
  • 99
  • 4
  • 14

1 Answers1

3

You can use built in pandas functionality for this. To illustrate:

import pandas as pd
import numpy as np

df = pd.DataFrame({'col1': np.random.rand(100),
              'col2': np.random.rand(100)})

# create a nan value in the 10th row of column 2
df.loc[10, 'col2'] = np.nan

pd.isnull(df.loc[10, :]) # will give true for col2
datawrestler
  • 1,527
  • 15
  • 17