Computer scienceData scienceInstrumentsPandasData preprocessing with pandas

Working with missing values

Proportions of NaNs

Report a typo

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 steps:

  1. Load the data into a pandas DataFrame.

  2. Calculate the proportion of missing values for each column in the dataframe using appropriate pandas methods.

  3. Round the calculated proportions of missing values to two decimal places (use pandas.DataFrame.round(decimals=...) to round values in the whole DataFrame or pandas.Series.round(decimals=...) to round values in the selected column).

  4. Print the result, ensuring that it follows the format shown in the example.

  5. Copy the printed result to the answer section.

Sample Input 1:

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

Sample Output 1:

year      0.20
degree    0.27
age       0.00
dtype: float64
Write code in your IDE to process the text file and display the results below
___

Create a free account to access the full topic