PYTHON PROGRAMMING
NaN means Not-a-Quantity. You should use it in numerical libraries — but additionally within the Python commonplace library.
NaN
stands for Not-a-Quantity. Thus, a NaN
object represents what this very identify conveys — one thing that isn’t a quantity. It may be a lacking worth but additionally a non-numerical worth in a numerical variable. As we shouldn’t use a non-numerical worth in purely numerical containers, we point out such a worth as not-a-number, NaN
. In different phrases, we are able to say NaN
represents a lacking numerical worth.
On this article, we’ll talk about NaN
objects out there within the Python commonplace library.
NaN
values happen ceaselessly in numerical information. In case you’re considering particulars of this worth, you will see them, as an illustration, right here:
On this article, we won’t talk about all the small print of NaN
values.¹ As a substitute, we’ll talk about a number of examples of how one can work with NaN
values in Python.
Every programming language has its personal strategy to NaN
values. In programming languages centered on computation, NaN
values are basic. For instance, in R, you’ve gotten NULL
(a counterpart of Python’s None
), NA
(for not out there), and NaN
(for not-a-number):
In Python, you’ve gotten None
and various objects representing NaN
. It’s value to know that Pandas differentiates between NaN
and NaT
, a worth representing lacking time. This text will talk about NaN
values in the usual library; NaN
(and NaT
, for that matter) within the mainstream numerical Python frameworks — resembling NumPy and Pandas — will likely be coated in a future article.
In case you haven’t labored with numerical information in Python, it’s possible you’ll not have encountered NaN
in any respect. Nevertheless, NaN
values are ubiquitous in Python programming, so it’s necessary to…