Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1.  
  2. """
  3. Created on Thu Nov 14 15:33:30 2019
  4.  
  5. @author: Gai nho Kiki
  6. """
  7.  
  8. import pandas as pd
  9. xl = pd.ExcelFile("SalesData.xlsx")
  10. SalesDatae = xl.parse("Orders")
  11. import pandas as pd
  12. import matplotlib.pyplot as plt
  13. import seaborn as sns
  14. xl = pd.ExcelFile("SalesData.xlsx")
  15. SalesData = xl.parse("Orders")
  16. print("------------------------------------")
  17. print("The total profit, sales, and discount that sold per year")
  18. SalesYear = SalesData
  19. SalesYear["Year"] = SalesYear["Order Date"].dt.year
  20. YearlySales = SalesYear [["Year", "Sales", "Discount", "Profit"]]
  21. YearlyTotalSales = YearlySales.groupby(by= "Year").sum()
  22. YearlyTotalSales = YearlyTotalSales.reset_index()
  23. print(YearlyTotalSales)
  24.  
  25.  
  26. print("------------------------------------")
  27. print("Top profitable products that sold with discount")
  28. print("---------------------------------")
  29. year_profit_discount = SalesData [[ "Sales","Sub-Category","Year", "Discount", "Profit"]]
  30. years = SalesData.Year.unique()
  31. for SalesYear in years:
  32. year_profit = year_profit_discount.loc[year_profit_discount["Discount"] != 0]
  33. year_profit = year_profit_discount.loc[year_profit_discount["Year"] == SalesYear]
  34. year_total_profit = year_profit.groupby(by = ["Sub-Category","Year"]).sum().sort_values(by = ["Profit", "Sales"], ascending=False)
  35. print("The top 10 profitable products with discount that sold the most in " + str(SalesYear) + " are: ")
  36. year_total_profit = year_total_profit.reset_index()
  37. print(year_total_profit.head(10))
  38.  
  39. print("---------------------------------")
  40. year_profit_discount = SalesData [["Year", "Sub-Category", "Sales", "Discount", "Profit"]]
  41. years = SalesData.Year.unique()
  42. for SalesYear in years:
  43. year_profit = year_profit_discount.loc[year_profit_discount["Discount"] != 0]
  44. year_profit = year_profit_discount.loc[year_profit_discount["Year"] == SalesYear]
  45. year_total_profit = year_profit.groupby(by = ["Sub-Category", "Year"]).sum().sort_values(by = "Profit", ascending = True)
  46. year_total_profit = year_profit.groupby(by = ["Sub-Category", "Year"]).sum().sort_values(by = "Sales")
  47. print("The top 10 profitable products with discount that sold the least in " + str(SalesYear) + " are: ")
  48. year_total_profit = year_total_profit.reset_index()
  49. print(year_total_profit.tail(10))
  50.  
  51.  
  52.  
  53. print("Least profitable products that sold Without Discount")
  54. print("---------------------------------")
  55. year_profit_wdiscount = SalesData [["Year", "Sub-Category", "Sales", "Discount", "Profit"]]
  56. years = SalesData.Year.unique()
  57. for SalesYear in years:
  58. year_profit = year_profit_discount.loc[year_profit_discount["Discount"] == 0]
  59. year_profit = year_profit_wdiscount.loc[year_profit_wdiscount["Year"] == SalesYear]
  60. year_total_profit = year_profit.groupby(by = ["Sub-Category", "Year"]).sum().sort_values(by = ["Profit", "Sales"], ascending = True)
  61. print("The least 10 profitable products without discount that sold the most in " + str(SalesYear) + " are: ")
  62. year_total_profit = year_total_profit.reset_index()
  63. print(year_total_profit.head(10))
  64.  
  65. print("---------------------------------")
  66. year_profit_wdiscount = SalesData [["Year", "Sub-Category", "Sales", "Discount", "Profit"]]
  67. years = SalesData.Year.unique()
  68. for SalesYear in years:
  69. year_profit = year_profit_discount.loc[year_profit_discount["Discount"] == 0]
  70. year_profit = year_profit_wdiscount.loc[year_profit_wdiscount["Year"] == SalesYear]
  71. year_total_profit = year_profit.groupby(by = ["Sub-Category", "Year"]).sum().sort_values(by = ["Profit", "Sales"], ascending = False)
  72. print("The least 10 profitable products without discount that sold the least in " + str(SalesYear) + " are: ")
  73. year_total_profit = year_total_profit.reset_index()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement