Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Tue Nov 12 20:57:47 2019
- @author: ronaldolegrama
- """
- import pandas as pd
- import matplotlib.pyplot as plt
- import seaborn as sns
- xl = pd.ExcelFile("SalesData.xlsx")
- SalesData = xl.parse("Orders")
- Decorating = "\n" + "*"*25 + "\n"
- #Top 10% product Sales by SEASON within the past 2 years:
- SalesMonth = SalesData
- SalesMonth["Month"] = SalesMonth["Order Date"].dt.quarter
- #.quarter = quarter
- #key error = most likely column error
- season_Sales_Cat = SalesData [["Month", "Sales", "Sub-Category",]]
- Months = SalesData.Month.unique()
- MostFrequent = SalesData["Sub-Category"].value_counts()
- total_products = MostFrequent.shape
- TopPercent = int (total_products[0]*.1)
- print(MostFrequent.head(TopPercent))
- for Month in Months:
- season_sales = season_Sales_Cat.loc[season_Sales_Cat["Month"] == Month]
- season_total_sales = season_sales.groupby(by = "Sub-Category").sum().sort_values(by = "Sales", ascending = False)
- season_total_sales = season_total_sales.reset_index()
- print("The top 10 subcategories with the most sales in Quarter " + str (Month) + " are: ")
- print(season_total_sales.head(10))
- print(Decorating)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement