Handle missing values

Report a typo

Load the given dataset into your IDE using pandas and get rid of missing values according to the following rules:

  • if a column has more than 7 NaNs, drop it;
  • if a column wasn't deleted at the previous step, fill NaNs with a median value.

Print the first 5 rows of the DataFrame and copy the result to the answer section.

Tip: thresh=N from dropna() requires that a column had at least N non-NaNs to survive

Sample Input 1:

brick,floor,totsp,price
NaN,11.0,199.0,8.5
0.0,8.0,102.0,7
1.0,17.0,51.0,NaN
NaN,19.0,137.0,6.7
0.0,15.0,207.0,NaN
NaN,12.0,87.0,7.1
1,17.0,179.0,NaN
0.0,9.0,241.0,84.0
1.0,11.0,237.0,NaN
NaN,14.0,70.0,8.7
0.0,7.0,210.0,NaN
NaN,1.0,107.0,9.9
NaN,15.0,71.0,5.4
0.0,15.0,138.0,8.3
0.0,12.0,98.0,NaN
0.0,9.0,108.0,5.3
NaN,8.0,219.0,81.7
0.0,12.0,237.0,79.6
1.0,12.0,64.0,NaN
NaN,7.0,239.0,73.5

Sample Output 1:

   floor  totsp  price
0   11.0  199.0    8.5
1    8.0  102.0    7.0
2   17.0   51.0    8.5
3   19.0  137.0    6.7
4   15.0  207.0    8.5
Write code in your IDE to process the text file and display the results below
___

Create a free account to access the full topic