Question: Task 1 : Aggregate Sales by Category In this task, you will be working with the 'HOP _ RBC _ Merchandise.xlsx ' . Read the
Task : Aggregate Sales by Category
In this task, you will be working with the 'HOPRBCMerchandise.xlsx Read the raw data into a Pandas DataFrame named 'salesdf Next, use 'salesdf to aggregate the total sales amount for each 'MerchandiseCategory'. In other words, you are to aggregate the sales by 'MerchandiseCategory'. The results should be stored in a Pandas DataFrame named 'categorysalesdf Print the DataFrame as the list step.
Note: if you want to rename the aggregated column then use this method:
categorysalesdfrenamecolumnsSaleAmount': 'TotalSalesAmount'
insert your code here
Task : 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 'MerchandiseCategory'. In essence, you are tasked with aggregating the number of items sold by 'MerchandiseCategory'. The results of this aggregation should be stored in a Pandas DataFrame named 'categorynumitemssolddf 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 : 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 'MerchandiseCategory and the other containing the number of items sold in each category. The resulting DataFrame should have three columns: 'MerchandiseCategory', 'TotalSalesAmount', 'and NumberofItemsSold'.
insert your code here
Task : Create Categories ie bins Based on Sales Amount
In this task, you will be enhancing the 'salesdf 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: $$$$ and $ Print 'salesdf at the end.
insert your code here
Task : Create Bins
In this task, you will be taking the 'salesdf DataFrame, which now includes the 'SaleAmountBin' 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 'MerchandiseCategory' and 'SaleAmountBin' 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. CopyPaste 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 MerchandiseCategory and SaleAmountBin, and count the number of items in each bin
itemcountbinsdf
salesdf
groupbyMerchandiseCategory', 'SaleAmountBin'
aggTransactionID: 'count'
renamecolumnsTransactionID: 'NumberofItemsSold'
resetindex
If this steps works correctly then you should see this output:
MerchandiseCategory SaleAmountBin NumberofItemsSold
Apparel $
Apparel $
Apparel $
Apparel $
Apparel $
BBQ Essentials $
BBQ Essentials $
BBQ Essentials $
BBQ Essentials $
BBQ Essentials $
Home & Kitchen $
Home & Kitchen $
Home & Kitchen $
Home & Kitchen $
Home & Kitchen $
Novelties $
Novelties $
Novelties $
Novelties $
Novelties $
insert your code here
Task : Transpose the Bins Into Columns
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
