Visualizations with Matplotlib

Explore the **Retail Performance Analysis** project, where you'll use Python's Matplotlib to visualize key metrics like sales, profit, and customer behavior. You'll analyze trends, identify top products, and understand the impact of discounts on profitability. This project is perfect for enhancing your data analysis skills and learning how to make data-driven decisions to optimize retail performance. Unlock valuable business insights in just a few steps! 📊🚀

All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.

All our activities include solutions with explanations on how they work and why we chose them.

codevalidated

Analyze the relationship between sales and profit to understand how sales performance impacts profitability. This is essential for identifying high-revenue products that may not necessarily contribute to high profits.

Your task is to use the scatter plot to visualize the relationship between sales and profit. Each point on the scatter plot represents an individual order, with sales on x-axis and profit on y-axis.

Set the

`alpha`

parameter to 0.5 to adjust the transparency of the points for better visualization.

codevalidated

Analyze the distribution of sales across different product categories to identify which categories drive the most revenue.

Instructions:

- Create a bar plot to show the total sales for each product category.
- Use the
`Category`

column for the x-axis and the sum of`Sales`

for the y-axis. - Add labels to the bars to indicate the total sales amount for each category.

codevalidated

Evaluate profit margins across different product sub-categories to identify areas where the business is most and least profitable.

Instructions:

- Create a horizontal bar plot showing the average profit margin for each product sub-category.
- Profit margin can be calculated as
`Profit / Sales`

. - Sort the sub-categories by profit margin in descending order.
- Set the color of the bars to 'lightgreen'.

codevalidated

Explore how discounting affects sales and profit by comparing sales and profit for different discount levels.

Instructions:

- Create a scatter plot with
`Discount`

on the x-axis and`Sales`

on the y-axis. - Color the points by profit (use a colormap) to see how discounts impact both sales and profit.

codevalidated

Compare sales and profit distributions across different regions to understand regional performance.

Instructions:

- Create a box plot to visualize the distribution of sales across different regions.
- Similarly, create another box plot for the distribution of profit across regions.
- Compare the two plots to draw insights about regional performance.
- Rotate the x-axis labels by 45 degrees for better readability.

codevalidated

** Step 1: Getting to Know Your Data** Before we start, let's take a moment to think about what we're looking for. Who are our top customers? How do they contribute to our total sales? By identifying these key players, we can understand where a significant portion of our revenue comes from.

** Step 2: Grouping and Summing Sales** We'll begin by grouping our data by Customer Name and summing up the Sales for each customer. This will give us a clear picture of who our top spenders are.

** Step 3: Creating the Plot** Now, let's visualize this data. In this step, you'll create a horizontal bar plot showing the top 10 customers and their total sales.

codevalidated

Let's explore how different customer segments (like Consumer, Corporate, and Home Office) contribute to our sales. This insight will help us tailor our marketing and sales strategies to each segment.

First, we'll group the data by `Segment`

and sum the `Sales`

for each segment to see which segment is the most lucrative.

Then, you'll create a pie chart to visualize the sales distribution across different customer segments.

codevalidated

** Shifting Focus to Profit** Now that we've seen how sales are distributed, let's shift our focus to profitability. Sometimes, high sales don't necessarily mean high profits. We'll explore which segments are truly driving profitability.

We'll follow a similar process as before, but this time we'll group by `Segment`

and sum the `Profit`

.

Then your task is to create a bar plot to visualize the profitability across different customer segments.

codevalidated

Now, let's take a look at the average discount given to each segment. Understanding discounting patterns across segments can provide insights into pricing strategies and customer behavior.

We’ll calculate the average discount for each segment by grouping the data by `Segment`

.

Then, you'll create a bar plot to visualize the average discount offered to each customer segment.

codevalidated

Finally, let's try to estimate the Customer Lifetime Value (CLV) for each segment. CLV is an essential metric that helps businesses understand the long-term value of their customers. We’ll estimate CLV based on average sales and profit per customer in each segment.

For this, first, we'll calculate the average sales and profit per customer in each segment. Then, we'll estimate the CLV by multiplying the average profit for each segment by the average sales for each segment.

After that your task is to create a horizontal bar plot to visualize the estimated CLV for each customer segment.

codevalidated

Let's begin by examining how sales vary month by month. The first step is to extract the month and year from the `Order Date`

column to create a new column called `Month-Year`

.

Now that we have the month-year information, we'll group the sales data by `Month-Year`

and sum the `Sales`

for each month. This will give us a clear picture of the monthly sales trend over the entire dataset.

After that, your task is to create a line plot to visualize the monthly sales trend.

codevalidated

Next, let's explore the trend in profitability over the same period. We’ll group the profit data by `Month-Year`

to see how it has fluctuated over time.

Your task is to create a line plot to visualize the monthly profit trend.

codevalidated

Now, let's analyze whether there are any seasonal patterns in sales. We’ll extract just the month from the `Order Date`

to see how sales vary across different times of the year.

Then, we'll group the sales data by `Month`

and calculate the average sales for each month. This will help us identify any seasonal trends in sales.

After that, your task is to create a bar plot to visualize the average sales by month.

codevalidated

Let’s repeat the seasonal analysis, but this time we’ll focus on profit to see if it follows the same seasonal patterns as sales.

Now, we'll group the data by `Month`

and calculate the total `Profit`

for each month using the `sum`

function and reset the index to create a DataFrame.

After that, your task is to create a bar plot to visualize the total profit by month.

codevalidated

Finally, let’s take a broader look at how sales and profit have changed over the years. We’ll extract the year from the `Order Date`

.

We’ll group the data by `Year`

to see overall trends in sales and profit over the years.

Your task is to create a dual-axis plot to visualize both sales and profit trends over the years.

codevalidated

** Discovering the Stars** 🌟 First things first, let’s find out which products are our top sellers. These are the products that customers can’t get enough of. We’ll start by summing up the sales for each product.

We've first grouped the data by `Product Name`

and calculated the total `Sales`

for each product. Then, we sorted the products based on sales in descending order and selected the top 10 products with the highest sales.

Now, your task is to create a horizontal bar plot to visualize the top-selling products and their total sales.

codevalidated

** Linking Inventory to Profit** 💡 Next up, let’s see how the quantity of products sold impacts overall profit. We’ll group by

`Product Name`

and sum up both `Quantity`

and `Profit`

.After that, your task is to create a scatter plot, where we can see the relationship between the number of products sold and the profit generated.

codevalidated

🔍 Now, let’s break down the performance by product category. We want to see which categories are driving the most sales and profit. We’ll group by `Category`

and sum up `Sales`

and `Profit`

.

Next, your task is to create a overlapping bar plot to compare the total sales and profit for each category.

codevalidated

** Getting Discount Savvy** 💸 We’ve seen how discounts can affect overall sales and profit, but what about specific products? Let’s analyze how discounts on different products impact profitability. We’ll calculate the average discount and total profit for each product.

After that, your task is to create a scatter plot, where we can see the relationship between average discount and total profit for each product.

codevalidated

** Preparing for the Future** Finally, let’s think about the future! We’ll use historical sales data to forecast demand for the top-selling products. This will help you plan inventory better and ensure you’re always stocked up on what customers want.

For this, first we'll filter the data to include only the top 10 best-selling products. Then, we'll group the data by `Month-Year`

and `Product Name`

to calculate the total `Quantity`

sold for each product in each month.

After that, your task is to create a line plot to visualize the demand forecast for the top-selling products over time.

codevalidated

💸 First, let’s explore how discounts are applied across different product categories. We’ll calculate the average discount for each category to see where discounts are being used the most.

For this, we'll group the data by `Category`

and calculate the average `Discount`

for each category.

After that, your task is to create a bar plot to visualize the average discount levels across different product categories.

codevalidated

** Do Discounts Drive Sales?** 🛒 Next, let’s analyze whether higher discounts are correlated with higher sales. We’ll calculate the total sales for different discount levels to see if there’s a sweet spot where discounts really boost sales.

For this, we'll group the data by `Discount`

and sum up the `Sales`

for each discount level.

After that, your task is to create a scatter plot to visualize the relationship between discount levels and total sales.

codevalidated

Let’s Talk Profit Margins 💰 Now that we’ve looked at sales, let’s shift our focus to profit. We’ll analyze how profit margins change across different discount levels to understand the trade-off between offering discounts and maintaining profitability.

First, we'll group the data by `Discount`

and calculate the sum of `Profit`

for each discount level.

After that, your task is to create a line plot to see how profit margins vary with different discount levels.

codevalidated

** Pricing Patterns** 🔍 Let’s evaluate the pricing strategies for different products. We’ll look at how the list price compares to the actual selling price after discounts to understand the impact of pricing strategies on sales and profit.

First, we've calculated the `Discounted Price`

for each product by applying the discount to the sales price.

Now, your task is to create a bar plot to compare the original sales (before discounts) with the discounted sales for a few key products.

Use the

`sample_products`

DataFrame to select the products for the plot that is already provided in the notebook.

codevalidated

🍬 Finally, let’s try to find the optimal discount level that maximizes both sales and profit. We’ll look at various discount levels to see where the balance lies.

First, we'll group the data by `Discount`

and calculate the total `Sales`

and `Profit`

for each discount level using the `sum`

function. Then, we'll create a new column `Profit Margin`

to calculate the profit margin percentage for each discount level.

After that, your task is to create a create a dual-axis plot to visualize both sales and profit margins across different discount levels.

This project is part of

Explore other projects