Computer scienceData scienceInstrumentsPandasData preprocessing with pandas

Working with missing values

How many columns have NaNs?

Report a typo

In this task, you are going to practice working with a dataset containing information about students. The dataset has three columns: year represents a student's year of study, degree represents their degree program, and age represents their age.

You must perform the following sequence of steps:

  1. Load the data into a pandas DataFrame.

  2. Count the number of columns in the DataFrame that contain missing values using appropriate pandas methods. The methods .isnull(), .any(), and .sum() will be particularly useful for this task.

  3. Insert the result, which is the count of columns containing missing values, in the answer section.

Sample Input 1:

year,age,degree
3,18,M
NaN,18,B
2,21,M
NaN,19,B
NaN,19,B
2,29,NaN
1,28,NaN
3,29,M
1,28,M
3,18,NaN
1,27,NaN
2,25,M
2,20,M
1,20,B
3,23,B

Sample Output 1:

2
Write code in your IDE to process the text file and display the results below
___

Create a free account to access the full topic