+2 votes
in Programming Languages by (73.2k points)

In my data, some values are NaN and my code fails because of those values. How can I check NaN values in the data?

1 Answer

+1 vote
by (346k points)
selected by
 
Best answer

There are functions in NumPy, math, and pandas libraries that you can use to check NaN values. Here is a simple example to check if a value is NaN.

>>> import math
>>> import numpy as np
>>> import pandas as pd

>>> t=float('nan')
>>> t
nan
>>> math.isnan(t)
True
>>> pd.isna(t)
True
>>> np.isnan(t)
True

>>> b=0.1
>>> np.isnan(b)
False
>>> math.isnan(b)
False
>>> pd.isna(b)
False

Related questions


...