0
0
Data Analysis Pythondata~30 mins

Dropping missing values (dropna) in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Dropping Missing Values with dropna
📖 Scenario: You work in a small shop that keeps track of daily sales data. Sometimes, some sales records are missing because the cashier forgot to enter them. You want to clean the data by removing these missing entries before analyzing the sales.
🎯 Goal: You will create a small sales data table with some missing values, then use a configuration variable to decide how to drop these missing values using dropna. Finally, you will display the cleaned data.
📋 What You'll Learn
Create a pandas DataFrame called sales_data with specific sales records including missing values
Create a variable called drop_axis to decide whether to drop rows or columns with missing values
Use dropna on sales_data with the axis=drop_axis parameter to remove missing values
Print the cleaned DataFrame
💡 Why This Matters
🌍 Real World
Cleaning data by removing missing values is a common first step before analyzing or visualizing data in many fields like sales, healthcare, and finance.
💼 Career
Data analysts and data scientists often need to handle missing data to ensure their models and reports are accurate and reliable.
Progress0 / 4 steps
1
Create the sales data with missing values
Create a pandas DataFrame called sales_data with these exact entries: columns 'Day', 'Sales', and 'Customers'. The data should be:
Day: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
Sales: [200, 220, null, 250, 270]
Customers: [20, null, 25, 30, null]
Use None for missing values.
Data Analysis Python
Hint

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

2
Set the axis to drop missing values
Create a variable called drop_axis and set it to 0 to drop rows with missing values.
Data Analysis Python
Hint

Set drop_axis to 0 to drop rows.

3
Drop missing values using dropna
Create a new DataFrame called cleaned_data by dropping missing values from sales_data using dropna with the parameter axis=drop_axis.
Data Analysis Python
Hint

Use dropna(axis=drop_axis) on sales_data.

4
Print the cleaned data
Print the cleaned_data DataFrame to see the result after dropping missing values.
Data Analysis Python
Hint

Use print(cleaned_data) to show the cleaned DataFrame.