Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Tue Nov 12 20:57:47 2019
  5.  
  6. @author: ronaldolegrama
  7. """
  8. import pandas as pd
  9. import matplotlib.pyplot as plt
  10. import seaborn as sns
  11. xl = pd.ExcelFile("SalesData.xlsx")
  12. SalesData = xl.parse("Orders")
  13. Decorating = "\n" + "*"*25 + "\n"
  14.  
  15. #Top 10% product Sales by SEASON within the past 2 years:
  16. SalesMonth = SalesData
  17. SalesMonth["Month"] = SalesMonth["Order Date"].dt.quarter
  18. #.quarter = quarter
  19. #key error = most likely column error
  20. season_Sales_Cat = SalesData [["Month", "Sales", "Sub-Category",]]
  21. Months = SalesData.Month.unique()
  22.  
  23. MostFrequent = SalesData["Sub-Category"].value_counts()
  24. total_products = MostFrequent.shape
  25. TopPercent = int (total_products[0]*.1)
  26.  
  27. print(MostFrequent.head(TopPercent))
  28.  
  29. for Month in Months:
  30. season_sales = season_Sales_Cat.loc[season_Sales_Cat["Month"] == Month]
  31. season_total_sales = season_sales.groupby(by = "Sub-Category").sum().sort_values(by = "Sales", ascending = False)
  32. season_total_sales = season_total_sales.reset_index()
  33. print("The top 10 subcategories with the most sales in Quarter " + str (Month) + " are: ")
  34. print(season_total_sales.head(10))
  35. print(Decorating)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement