How Does Nan Happen

How Does Nan Happen

What is NaN ? NaN, acronym for “Not a Number” is an exception which usually occurs in the cases when an expression results in a number that can’t be represented. For example square root of negative numbers.

What can I replace NaN with?

  • For one column using pandas: df[‘DataFrame Column’] = df[‘DataFrame Column’].fillna(0)
  • For one column using numpy: df[‘DataFrame Column’] = df[‘DataFrame Column’].replace(np.nan, 0)
  • For the whole DataFrame using pandas: df.fillna(0)
  • For the whole DataFrame using numpy: df.replace(np.nan, 0)

How do I know if I have NaN?

isNaN() method determines whether a value is NaN (Not-A-Number). This method returns true if the value is of the type Number, and equates to NaN. Otherwise it returns false. Number.

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.