AMZ DIGICOM

Digital Communication

AMZ DIGICOM

Digital Communication

Presentation of the Pandas Isna () function

PARTAGEZ

The Python Pandas function DataFrame.isna() Allows you toIdentify missing data (NaN Or None) in a dataframe. This may be useful for determining whether analyzes can take place or whether data cleaning is necessary beforehand.

Web accommodation

Flexible, efficient and safe web accommodation

  • SSL certificate and DDOS protection
  • Data backup and restoration
  • Assistance 24/7 and personal advisor

Pandas syntax isna()

Like pandas isna() Do not take parametersthe syntax of the function is very simple and looks like this:

Function application isna()

Pandas isna() is applied to a dataframa to create a new dataframe with Boolean values. If a value is missing in the original dataframa, or if it is NaN Or Nonethe value True is stored at the corresponding location in the result. Otherwise, isna() Returns the value False to the corresponding position.

Note

If you want not only to identify the values NaN Or Nonebut also delete them, consult our article on the Pandas function dropna(). And if you want to systematically replace the values, discover the function fillna().

Identification of missing values ​​in a dataaframa

In the following examples, we consider a dataframa containing information on different people, but in which certain data is missing or have the value None ::

import pandas as pd
# Création d’un DataFrame d’exemple
données = {
    'Nom': ['Alice', 'Bob', None, 'David'],
    'Âge': [25, None, 35, 40],
    'Ville': ['New York', 'Los Angeles', 'Chicago', None]
}
df = pd.DataFrame(données)
print(df)

python

Dataframa presents itself as follows:

Nom   Âge       Ville
0  Alice  25.0    New York
1    Bob   NaN  Los Angeles
2   None  35.0     Chicago
3  David  40.0        None

To find out exactly what values ​​are missing, isna() can be called on data.

# Application de la fonction isna() de Pandas
missing_values = df.isna()
print(missing_values)

python

The call for function returns a new data in which a value is replaced by True If the original value is missing, and by False If the value is present. The result therefore presents itself as follows:

Nom    Âge  Ville
0  False  False  False
1  False   True  False
2   True  False  False
3  False  False   True

Count the missing values ​​by column

It may be useful to know how many values ​​are lacking in each column to decide how to process missing data. For this, Pandas isna() can be used in combination with the Python function sum().

# Compter les valeurs manquantes par colonne
missing_count = df.isna().sum()
print(missing_count)

python

The result indicates how many values ​​are lacking in each column:

Nom      1
Âge      1
Ville    1
dtype: int64

Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact