0
0
Pandasdata~15 mins

Filling missing values with fillna() in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Filling missing values with fillna()
📖 Scenario: You work in a small shop that keeps track of daily sales in a table. Sometimes, the sales data is missing for some days. You want to fill those missing sales numbers with zero so you can calculate total sales easily.
🎯 Goal: Build a small program that creates a sales data table with some missing values, sets a fill value, fills the missing values using fillna(), and then shows the updated table.
📋 What You'll Learn
Create a pandas DataFrame called sales_data with the exact data given.
Create a variable called fill_value and set it to 0.
Use fillna() on sales_data with fill_value to fill missing values and save it as filled_sales.
Print the filled_sales DataFrame.
💡 Why This Matters
🌍 Real World
In real life, sales or sensor data often have missing values. Filling them with a default value helps keep calculations accurate and avoids errors.
💼 Career
Data analysts and scientists frequently clean data by filling missing values before analysis or building models.
Progress0 / 4 steps
1
Create the sales data with missing values
Create a pandas DataFrame called sales_data with these exact values: the column 'Day' with values ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'] and the column 'Sales' with values [200, None, 150, None, 300].
Pandas
Need a hint?

Use pd.DataFrame with a dictionary for columns. Use None for missing values.

2
Set the fill value
Create a variable called fill_value and set it to 0.
Pandas
Need a hint?

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

3
Fill missing values using fillna()
Use fillna() on sales_data with fill_value to fill missing values. Save the result in a new variable called filled_sales.
Pandas
Need a hint?

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

4
Print the filled sales data
Print the filled_sales DataFrame to see the missing values replaced with zero.
Pandas
Need a hint?

Use print(filled_sales) to show the DataFrame.