0
0
Pandasdata~30 mins

Outlier detection with IQR in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Outlier detection with IQR
📖 Scenario: You work as a data analyst for a retail company. You have sales data for different stores. Sometimes, some sales numbers are unusually high or low. These are called outliers. Detecting outliers helps you understand if there are errors or special cases in the data.
🎯 Goal: You will learn how to detect outliers in sales data using the Interquartile Range (IQR) method with pandas. You will create the sales data, calculate IQR, find outliers, and display them.
📋 What You'll Learn
Use pandas to create and analyze data
Calculate quartiles and IQR
Detect outliers using IQR method
Print the detected outliers
💡 Why This Matters
🌍 Real World
Outlier detection helps businesses find unusual data points that may indicate errors, fraud, or special events.
💼 Career
Data analysts and data scientists often use IQR to clean data and improve the quality of their analysis.
Progress0 / 4 steps
1
Create sales data with pandas
Create a pandas DataFrame called sales_data with one column named sales and these exact values: 100, 150, 200, 250, 300, 350, 400, 1000.
Pandas
Need a hint?

Use pd.DataFrame with a dictionary where the key is "sales" and the value is the list of numbers.

2
Calculate Q1, Q3 and IQR
Create three variables: Q1, Q3, and IQR. Calculate Q1 as the 25th percentile of sales_data["sales"], Q3 as the 75th percentile, and IQR as Q3 - Q1.
Pandas
Need a hint?

Use the quantile() method on the sales column to get Q1 and Q3.

3
Detect outliers using IQR
Create a variable called outliers that contains the rows from sales_data where the sales value is less than Q1 - 1.5 * IQR or greater than Q3 + 1.5 * IQR.
Pandas
Need a hint?

Use boolean conditions combined with | inside the DataFrame filter brackets.

4
Print the detected outliers
Write a print statement to display the outliers DataFrame.
Pandas
Need a hint?

Use print(outliers) to show the rows with outliers.