Calculating the Number of Missing Values
It should be noted that it isn't convenient to check each value of the dataset for the NaN. It is more convenient to see the number of missing values to conclude columns where we have NaNs.
As you remember, we have two functions to check for the missing values. To calculate the sum, just use the .sum()
function. Thus, in general, we have 2 options for outputting the number of NaNs for each column:
python91234data.isna().sum()# Ordata.isnull().sum()
Okay, nothing complicated. Let's move on the task.
Tarea
Swipe to start coding
- Calculate the number of missing values for the dataset using one of the mentioned functions.
- Output the result.
Try to draw your own conclusions.
Solución
9
1
2
3
4
5
6
7
8
9
import pandas as pd
data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/4bf24830-59ba-4418-969b-aaf8117d522e/titanic_0.csv')
# Calculate the number of missing values
Nan = data.isna().sum()
# Output the result
print(Nan)
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 5. Capítulo 2
single
9
1
2
3
4
5
6
7
8
9
import pandas as pd
data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/4bf24830-59ba-4418-969b-aaf8117d522e/titanic_0.csv')
# Calculate the number of missing values
Nan = ___
# Output the result
___
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla