Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python code please for the commented steps Handling Missing Values 2 of the columns have a relatively small amount of null values. There are 110

image text in transcribedimage text in transcribedPython code please for the commented steps

Handling Missing Values 2 of the columns have a relatively small amount of null values. There are 110 null values in the so (Strike Outs) column and 22 in the DP (Double Play) column. Two of the columns have a relatively large amount of them. There are 419 null values in the cs (Caught Stealing) column and 1777 in the P (Hit by Pitch) column. 1 df_Teams.isna( ).sum () [51] 1 \#Identifying the number of null values in the dataframe 2 \# Creating a for loop to display the column names and also their count of missing values 3 4 \#\#\#\# complete the code below 5 \#\#\#\# create an empty list named 'names' for columns names 6 7 \#\#\#\# create an empty list named 'val' for \# of null values in each column 8 9 10 \#\#\#\# create a for loop iterating each 'col' through 'df.columns' 11 for col in df.columns : 12 \#\#\#\# add column name 'col' to 'names' 13 \# Adding the column name to the names list 14 \#\#\#\# add \# of null values to 'val' \#\#\#\# you can get \# of null values for column ' c ' as ' df[c].isnull().sum() \# Adding the count of the missing values \#\#\#\# print out results as (column_name, \# of null values in column_name) \#\#\#\# Note that 'col' is the current column_name in iteration \#\#\#\# and you should retrieve the \# of null values in column_name as the last element in 'val' \#\#\#\# hint: the last element in a list 1 is: 1[1] \$\# Printing the column names and thier missing counts ie : 2 lists We are going to drop two columns ( S and ) with too many missing values. NOTE: even though we said that dropping columns with missing values is the last resort, the reason we are dropping the columns here is that because of the number of missing values, it will be very difficult for us to impute them in these two columns. [ ] 1 \#Dropping the columns with large number of null values 2 3 4 \#\#\#\# drop 'CS' \& 'HBP' from ' df 5 \#\#\#\# and save the remaining as 'df' 6 7 8 \#\#\#\# check the first 5 rows of the new 'df' to see 9 \#\#\#\# if the two columns are successfully dropped 10 \#\#\#\# you should expect to see 27 columns now 11 With the two columns dropped, we can impute the missing values in the other two columns ( so and DP ) since they have much less

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

User Defined Tensor Data Analysis

Authors: Bin Dong ,Kesheng Wu ,Suren Byna

1st Edition

3030707490, 978-3030707491

More Books

Students also viewed these Databases questions