0
0
Pandasdata~30 mins

Combining multiple cleaning steps in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Combining multiple cleaning steps
📖 Scenario: You have a small sales dataset with some missing values and inconsistent text. You want to clean it so it is easier to analyze.
🎯 Goal: Build a pandas DataFrame with sales data, then clean it by filling missing values and fixing text formatting in one combined step.
📋 What You'll Learn
Create a pandas DataFrame with given sales data
Create a variable for the fill value for missing sales
Use a single chained pandas command to fill missing sales and fix product names
Print the cleaned DataFrame
💡 Why This Matters
🌍 Real World
Cleaning data is a common first step in data science to prepare messy real-world data for analysis.
💼 Career
Data scientists and analysts often combine multiple cleaning steps to make data consistent and ready for insights.
Progress0 / 4 steps
1
Create the sales DataFrame
Create a pandas DataFrame called sales with these exact columns and values:
{'Product': ['apple', 'Banana', 'orange', 'banana', 'Apple'], 'Sales': [10, 15, None, 20, None]}
Pandas
Need a hint?

Use pd.DataFrame() with a dictionary for columns.

2
Set the fill value for missing sales
Create a variable called fill_value and set it to 0 to use for filling missing sales values.
Pandas
Need a hint?

Just assign 0 to fill_value.

3
Clean the sales DataFrame
Create a new DataFrame called cleaned_sales by filling missing values in sales['Sales'] with fill_value and making all sales['Product'] names lowercase in one combined command using method chaining.
Pandas
Need a hint?

Use assign() to change Product to lowercase and fillna() to fill missing Sales, chaining them together.

4
Print the cleaned DataFrame
Print the cleaned_sales DataFrame to see the cleaned data.
Pandas
Need a hint?

Use print(cleaned_sales) to show the cleaned DataFrame.