Pandas isna() and isnull(), what is the difference?

PythonPandas

Python Problem Overview


Pandas has both isna() and isnull(). I usually use isnull() to detect missing values and have never met the case so that I had to use other than that. So, when to use isna()?

Python Solutions


Solution 1 - Python

isnull is an alias for isna. Literally in the code source of pandas:

isnull = isna

Indeed:

>>> pd.isnull
<function isna at 0x7fb4c5cefc80>

So I would recommend using isna.

Solution 2 - Python

They both are same. As a best practice, always prefer to use isna() over isnull().

It is easy to remember what isna() is doing because when you look at numpy method np.isnan(), it checks NaN values. In pandas there are other similar method names like dropna(), fillna() that handles missing values and it always helps to remember easily.

Solution 3 - Python

The documentation for both is literally identical.

pandas.isna() : https://pandas.pydata.org/pandas-docs/stable/generated/pandas.isna.html#pandas.isna

pandas.isnull() : https://pandas.pydata.org/pandas-docs/stable/generated/pandas.isnull.html#pandas.isnull

In here, it even says DataFrame.isnull is an alias of isna in See also section.

pandas.DataFrame.isnull(): https://pandas-docs.github.io/pandas-docs-travis/generated/pandas.DataFrame.isnull.html#pandas.DataFrame.isnull

Therefore, they must be the same thing, like np.nan, np.NaN, np.NAN.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionipramusintoView Question on Stackoverflow
Solution 1 - PythonqsantosView Answer on Stackoverflow
Solution 2 - PythonJyoti Prasad PalView Answer on Stackoverflow
Solution 3 - PythonTam LeView Answer on Stackoverflow