0

.isnull() vs .isna() for pandas.

Sample code:

import pandas as pd
import numpy as np

df = pd.DataFrame({ 'object': ['a', 'b', 'c',pd.NA],
                   'numeric': [1, 2, np.nan , 4],
                 })

creates data frame df that looks like:

|    | object   |   numeric | categorical   |
|---:|:---------|----------:|:--------------|
|  0 | a        |         1 | d             |
|  1 | b        |         2 | nan           |
|  2 | c        |       nan | f             |
|  3 | <NA>     |         4 | g             |

Testing .isnull() and .isna():

pd.isnull(df.iloc[3,0])
Out[165]: True

pd.isnull(df.iloc[2,1])
Out[166]: True

pd.isna(df.iloc[3,0])
Out[167]: True

pd.isna(df.iloc[2,1])
Out[168]: True

Here both .isnull() and .isna() give same result.

Question: Which one to use with pandas and why to use? What are main advantages and disadvantages of each of them with pandas?

vasili111
  • 6,032
  • 10
  • 50
  • 80
  • `isnull` is an alias of `isna`. [The documentation states this.](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.isna.html) – user3483203 Feb 07 '20 at 15:15
  • Copy of [this](https://datascience.stackexchange.com/questions/37878/difference-between-isna-and-isnull-in-pandas) – nakE Feb 07 '20 at 15:16
  • Use `isna` as it is two characters shorter than `isnull` and therefore cooler – piRSquared Feb 07 '20 at 15:16
  • Found answer here justt now: https://stackoverflow.com/questions/60101845/compare-multiple-pandas-columns-1st-and-2nd-after-3rd-and-4rth-after-etc-wit/60102672?noredirect=1#comment106324219_60102672 – vasili111 Feb 07 '20 at 15:16
  • 1
    Next time, please do a Google search before posting posts. – nakE Feb 07 '20 at 15:17
  • @nakE I did but could not find. – vasili111 Feb 07 '20 at 15:18
  • If you google the title of your question, the first two results both give the correct answer. The next place you should look is the documentation, which also gives the correct answer, and next, [the code](https://github.com/pandas-dev/pandas/blob/29d6b0232aab9576afa896ff5bab0b994760495a/pandas/core/generic.py#L7269), which also shows they are the exact same. – user3483203 Feb 07 '20 at 15:20
  • @Rene it's the other way around. – user3483203 Feb 07 '20 at 15:33

0 Answers0