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''

0

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.