Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1.  
  2.  
  3. #Product Sales by Region with most profit
  4.  
  5. #find which region has the most sales
  6. region_profit_columns = SalesData [["Region", "Sales"]]
  7.  
  8. region_total_sales = region_profit_columns.groupby(by = "Region").sum().sort_values(by = "Sales")
  9. print(region_total_sales)
  10.  
  11. #find which region has the most profit
  12. region_profit_columns = SalesData [["Region", "Profit"]]
  13. region_total_profit = region_profit_columns.groupby(by = "Region").sum().sort_values(by = "Profit")
  14. print(region_total_profit)
  15.  
  16. #find product sales by region
  17. region_profit_subCat = SalesData [["Region", "Profit", "Sub-Category"]]
  18. regions = SalesData.Region.unique()
  19.  
  20. #for each value in regions:
  21. for region in regions:
  22. region_profit = region_profit_subCat.loc[region_profit_subCat["Region"] == region]
  23. region_total_profit = region_profit.groupby(by = "Sub-Category").sum().sort_values(by = "Profit", ascending = False)
  24. region_total_profit = region_total_profit.reset_index()
  25. print("The most profitable 5 sub-categories in " + region + " are: ")
  26. print(region_total_profit.head(5))
  27. print(Decorating)
  28.  
  29.  
  30. """
  31. Created on Thu Nov 14 15:33:30 2019
  32.  
  33. @author: Gai
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement