Cleanse Missing Data Using the pandas Python Package

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

In this lab, we will load a CSV file into a pandas DataFrame. Once loaded, we will count the number of missing values in the file. Next, we will drop any columns that are missing all values, and replace any remaining missing values.

Basic Python programming skills will be required for this lab. If you need a refresher, check out the following course:
– [Certified Associate in Python Programming Certification](https://acloud.guru/overview/8169e8e7-91a7-4d92-b278-4dd08c787dc6)

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Load the Data File

Load the missing-data.csv file into a pandas DataFrame, and count the number of missing values.

Drop Any Columns That Are Missing All Values

Make sure to drop only columns that are missing all values.

Replace Remaining Missing Values with the Last Valid Observed Value of That Column

This will leave some missing values at the beginning, as there was no last valid observed value.

Write the Data to a New File

Write the data to a new file named cleaned_data.csv.

Additional Resources

The Scenario

You are working as a database admin, and while attempting to load a CSV data file, you discover it has several missing values. Thankfully, you have learned some methods to resolve missing data from the awesome courses on acloud.guru!

You will take the following steps to clean up the missing values:

  • Load the CSV file into a DataFrame.
  • Drop any columns that are missing all values.
  • Replace any remaining missing values with the last valid observed value of that column.
    • Note: This will leave some missing values at the beginning, as there was no last valid observed value.
  • Write the data to a new file.

Log in to the server over SSH using the credentials provided.

The missing-data.csv file is already available in the lab instance, but if you'd like to follow along on another machine, you may download it from here.

This data was sourced from the Center for Machine Learning and Intelligent Systems. Learn more here.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?