w3resource

Pandas Pivot Titanic: Check missing values of children


17. Pivot Table: Check Missing Values of Children

Write a Pandas program to create a Pivot table and check missing values of children. Go to Editor

Sample Solution:

Python Code :

import pandas as pd
import numpy as np
df = pd.read_csv('titanic.csv')
result = df.loc[df['who']=='child'].isnull().sum()
print(result)

Sample Output:

survived        0
pclass          0
sex             0
age             0
sibsp           0
parch           0
fare            0
embarked        0
class           0
who             0
adult_male      0
deck           70
embark_town     0
alive           0
alone           0
Unnamed: 15    83
dtype: int64        

For more Practice: Solve these Related Problems:

  • Write a Pandas program to create a pivot table that counts missing age values in the children category from titanic.csv.
  • Write a Pandas program to generate a pivot table that highlights the number of missing entries for children in each class or gender.
  • Write a Pandas program to build a pivot table to display missing age counts among children passengers grouped by cabin class.
  • Write a Pandas program to create a pivot table that segregates records with missing age data for children and computes their frequencies.

Python Code Editor:


Pivot Titanic.csv:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to create a Pivot table and find number of adult male, adult female and children.
Next: Write a Pandas program to create a Pivot table and separate the gender according to whether they traveled alone or not to get the probability of survival.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.