0
0
Pandasdata~30 mins

NaN and None in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Handling NaN and None in Pandas
📋 What You'll Learn
💡 Why This Matters
🌍 Real World
Handling missing data is common in real-world datasets like sales, weather, or survey data where some entries might be missing or not recorded.
💼 Career
Data scientists and analysts must know how to detect and handle missing values to prepare clean data for analysis and modeling.
Progress0 / 4 steps
1
Create a DataFrame with missing values
Import pandas as pd and numpy as np. Create a DataFrame called sales_data with a column 'Day' containing 'Monday', 'Tuesday', 'Wednesday', 'Thursday', and 'Friday'. Add a column 'Sales' with values 200, None, 150, np.nan, and 300 respectively.
Pandas
Need a hint?

Use pd.DataFrame to create the table. Use None and np.nan to represent missing values.

2
Count missing values in the DataFrame
Create a variable called missing_count that stores the total number of missing values in the sales_data DataFrame using the isna() and sum() methods.
Pandas
Need a hint?

Use sales_data.isna() to find missing values, then sum twice to get total count.

3
Remove rows with missing values
Create a new DataFrame called clean_sales by removing all rows with missing values from sales_data using the dropna() method.
Pandas
Need a hint?

Use dropna() on the DataFrame to remove rows with missing values.

4
Print the cleaned DataFrame
Print the clean_sales DataFrame to show the sales data without missing values.
Pandas
Need a hint?

Use print(clean_sales) to display the DataFrame without missing values.