0
0
Data Analysis Pythondata~15 mins

Filling missing values (fillna) in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Filling Missing Values (fillna)
📖 Scenario: Imagine you work for a small online store. You have a table of sales data, but some sales amounts are missing. You want to fill these missing values with zero so you can calculate total sales without errors.
🎯 Goal: You will create a small sales data table with missing values, set a fill value, fill the missing values using fillna, and then print the cleaned data.
📋 What You'll Learn
Create a pandas DataFrame with missing values
Create a variable to hold the fill value
Use the fillna method to fill missing values
Print the cleaned DataFrame
💡 Why This Matters
🌍 Real World
Cleaning missing data is a common task in data analysis to prepare data for calculations and visualizations.
💼 Career
Data analysts and scientists often need to handle missing data to ensure accurate reports and models.
Progress0 / 4 steps
1
Create sales data with missing values
Create a pandas DataFrame called sales_data with one column named 'sales' and these values: 100, None, 250, None, 400.
Data Analysis Python
Hint

Use pd.DataFrame with a dictionary where the key is 'sales' and the value is the list of numbers including None for missing values.

2
Set the fill value
Create a variable called fill_value and set it to 0 to use for filling missing sales.
Data Analysis Python
Hint

Just create a variable named fill_value and assign 0 to it.

3
Fill missing values using fillna
Create a new DataFrame called cleaned_sales by filling missing values in sales_data using the fillna method with the variable fill_value.
Data Analysis Python
Hint

Use sales_data.fillna(fill_value) and assign it to cleaned_sales.

4
Print the cleaned sales data
Print the cleaned_sales DataFrame to see the missing values replaced by zero.
Data Analysis Python
Hint

Use print(cleaned_sales) to display the DataFrame.