0
0
Pandasdata~30 mins

Box plots in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Box plots
📖 Scenario: You work as a data analyst for a small company. You have collected sales data for different products over several months. You want to understand the spread and distribution of sales numbers to find out if there are any unusual values or differences between products.
🎯 Goal: Build a simple program that creates a box plot to visualize the sales data for different products using pandas.
📋 What You'll Learn
Create a pandas DataFrame with sales data for three products over five months.
Set a configuration variable for the column names to plot.
Use pandas box plot function to create the box plot for the selected products.
Print the box plot object to confirm the plot was created.
💡 Why This Matters
🌍 Real World
Box plots help analysts quickly see the distribution, spread, and outliers in sales or other numeric data, which is useful for business decisions.
💼 Career
Data analysts and scientists often use box plots to summarize data distributions and detect unusual values before deeper analysis.
Progress0 / 4 steps
1
Create the sales data DataFrame
Create a pandas DataFrame called sales_data with these exact values: columns 'Month', 'Product_A', 'Product_B', 'Product_C'. The 'Month' column should have values ['Jan', 'Feb', 'Mar', 'Apr', 'May']. The sales numbers for 'Product_A' are [100, 120, 130, 90, 110], for 'Product_B' are [80, 85, 88, 90, 95], and for 'Product_C' are [150, 160, 170, 165, 155]. Import pandas as pd first.
Pandas
Need a hint?

Use pd.DataFrame with a dictionary where keys are column names and values are lists of data.

2
Set the columns to plot
Create a list variable called products that contains the exact strings 'Product_A', 'Product_B', and 'Product_C'. This list will be used to select columns for the box plot.
Pandas
Need a hint?

Just create a list with the exact product column names.

3
Create the box plot
Use the boxplot method on sales_data to create a box plot for the columns in the products list. Save the result in a variable called boxplot_result.
Pandas
Need a hint?

Use sales_data.boxplot(column=products) to create the box plot.

4
Display the box plot result
Print the boxplot_result variable to show the box plot object.
Pandas
Need a hint?

Use print(boxplot_result) to display the plot object.