0
0
Data Analysis Pythondata~30 mins

Categorical plots (boxplot, violinplot) in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Exploring Categorical Plots: Boxplot and Violinplot
📖 Scenario: You work as a data analyst for a small bakery. You have collected data on the number of pastries sold each day, categorized by pastry type. You want to understand the sales distribution for each pastry type to help the bakery decide which pastries are popular and how consistent their sales are.
🎯 Goal: Build a Python program that creates a dataset of pastry sales, sets up a configuration for plot style, then uses categorical plots (boxplot and violinplot) to visualize the sales distribution by pastry type.
📋 What You'll Learn
Create a pandas DataFrame with pastry sales data
Set a plot style configuration variable
Use seaborn to create a boxplot and a violinplot
Display the plots
💡 Why This Matters
🌍 Real World
Categorical plots like boxplots and violinplots help businesses understand how different categories perform and how consistent their data is, which supports better decision-making.
💼 Career
Data analysts and scientists use these plots to summarize and communicate insights about grouped data in reports and presentations.
Progress0 / 4 steps
1
Create the pastry sales data
Create a pandas DataFrame called sales_data with two columns: 'Pastry' and 'Sales'. The data should have these exact rows: 'Croissant', 30, 'Croissant', 45, 'Croissant', 40, 'Donut', 50, 'Donut', 55, 'Donut', 60, 'Muffin', 20, 'Muffin', 25, 'Muffin', 22.
Data Analysis Python
Hint

Use pd.DataFrame with a dictionary containing the two columns and their values.

2
Set the plot style configuration
Create a variable called plot_style and set it to the string 'whitegrid' to configure the seaborn plot style.
Data Analysis Python
Hint

Just assign the string 'whitegrid' to the variable plot_style.

3
Create boxplot and violinplot
Import seaborn as sns and matplotlib.pyplot as plt. Use sns.set_style(plot_style) to apply the style. Then create a boxplot with sns.boxplot using sales_data, setting x='Pastry' and y='Sales'. Next, create a violinplot with sns.violinplot using the same parameters. Use plt.show() to display the plots.
Data Analysis Python
Hint

Use sns.set_style(plot_style) before plotting. Create the boxplot and violinplot with x='Pastry' and y='Sales'. Use plt.show() to display each plot.

4
Display the plots
Run the program to display the boxplot and violinplot showing the sales distribution for each pastry type.
Data Analysis Python
Hint

Make sure to run the entire program to see both plots displayed one after the other.