Question: Task 1 : Aggregate Sales by Category In this task, you will be working with the 'HOP _ RBC _ Merchandise.xlsx ' . Read the

Task 1: Aggregate Sales by Category
In this task, you will be working with the 'HOP_RBC_Merchandise.xlsx'. Read the raw data into a Pandas DataFrame named 'sales_df'. Next, use 'sales_df' to aggregate the total sales amount for each 'Merchandise_Category'. In other words, you are to aggregate the sales by 'Merchandise_Category'. The results should be stored in a Pandas DataFrame named 'category_sales_df'. Print the DataFrame as the list step.
Note: if you want to rename the aggregated column then use this method:
category_sales_df.rename(columns={'Sale_Amount': 'Total_Sales_Amount'})
insert your code here
Task 2: Count Items Sold by Category
In this task, you will continue working with the Merchandise data, but this time your focus will be on counting the number of sales transactions for each 'Merchandise_Category'. In essence, you are tasked with aggregating the number of items sold by 'Merchandise_Category'. The results of this aggregation should be stored in a Pandas DataFrame named 'category_num_items_sold_df'. As the final step, you will print this DataFrame to display the number of items sold in each merchandise category.
insert your code here
Task 3: Merge the Total Sales and Item Count DataFrames
In this task, you will build upon your previous work. Your objective is to merge two DataFrames that you have previously created: one containing the total sales amount for each 'Merchandise_Category and the other containing the number of items sold in each category. The resulting DataFrame should have three columns: 'Merchandise_Category', 'Total_Sales_Amount', 'and Number_of_Items_Sold'.
insert your code here
Task 4: Create Categories (i.e. bins) Based on Sales Amount
In this task, you will be enhancing the 'sales_df' DataFrame by adding a new column that categorizes each sale amount into predefined bins. These bins will represent ranges of sale amounts, allowing for easier analysis of the sales data. Specifically, the sale amounts will be categorized into the following bins: '$0-19.99','$20-39.99','$40-59.99','$60-79.99', and '$80-99.99'. Print 'sales_df' at the end.
insert your code here
Task 5: Create Bins
In this task, you will be taking the 'sales_df' DataFrame, which now includes the 'Sale_Amount_Bin' column, and further aggregating the data to gain insights into the sales distribution across different merchandise categories and sale amount bins. Specifically, you will group the data by both 'Merchandise_Category' and 'Sale_Amount_Bin' and then count the number of items sold within each group.
This this is a little more complex than the examples in the lesson so I will provide the code for this one below. Copy/Paste this into your code. Be sure to compare this back to the aggregations in the lessons to see how it differs. Notice how I break break this long statement down across lines. This is just for readability.
# Aggregate the data by Merchandise_Category and Sale_Amount_Bin, and count the number of items in each bin
item_count_bins_df =(
sales_df
.groupby(['Merchandise_Category', 'Sale_Amount_Bin'])
.agg({'Transaction_ID': 'count'})
.rename(columns={'Transaction_ID': 'Number_of_Items_Sold'})
.reset_index()
)
If this steps works correctly then you should see this output:
Merchandise_Category Sale_Amount_Bin Number_of_Items_Sold
0 Apparel $0-19.995
1 Apparel $20-39.9920
2 Apparel $40-59.9919
3 Apparel $60-79.990
4 Apparel $80-99.990
5 BBQ Essentials $0-19.9935
6 BBQ Essentials $20-39.9910
7 BBQ Essentials $40-59.996
8 BBQ Essentials $60-79.990
9 BBQ Essentials $80-99.990
10 Home & Kitchen $0-19.9921
11 Home & Kitchen $20-39.9939
12 Home & Kitchen $40-59.990
13 Home & Kitchen $60-79.990
14 Home & Kitchen $80-99.990
15 Novelties $0-19.9945
16 Novelties $20-39.990
17 Novelties $40-59.990
18 Novelties $60-79.990
19 Novelties $80-99.990
insert your code here
Task 6: Transpose the Bins Into Columns

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!