Guest User

Untitled

a guest
Dec 3rd, 2019
88
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. xl = pd.ExcelFile("SalesData.xlsx")
  3. SalesDatae = xl.parse("Orders")
  4. import pandas as pd
  5. xl = pd.ExcelFile("SalesData.xlsx")
  6. SalesData = xl.parse("Orders")
  7.  
  8. def profit_SubMenu ():
  9. Decorating = "\n" + "*"*45 + "\n"
  10. print("Sumarization of the profit, sales, and discount that sold in the past 4 years: ")
  11. SalesYear = SalesData
  12. SalesYear["Year"] = SalesYear["Order Date"].dt.year
  13. YearlySales = SalesYear [["Year", "Sales", "Profit"]]
  14. YearlyTotalSales = YearlySales.groupby(by= "Year").sum()
  15. YearlyTotalSales = YearlyTotalSales.reset_index()
  16. print(YearlyTotalSales)
  17. print(Decorating)
  18.  
  19. required_input = 1
  20. while required_input == 1:
  21. profit_SubMenu = input ("Please select a number from 1 to 3 below: \n [1] The top 5 profitable products and its sale data \n [2] The least 5 profitable products and its sale data \n [3] Main menu \n Please enter here: ")
  22. if not profit_SubMenu:
  23. profit_SubMenu = input("Input value cannot be blank or space. Please re-enter a number from 1 to 4: ")
  24. continue
  25. if not profit_SubMenu.isdigit():
  26. profit_SubMenu = input ("Input must be numerical value. Please re-enter a number from 1 to 4: ")
  27. continue
  28. profit_SubMenu = int(profit_SubMenu)
  29. if not profit_SubMenu > 0:
  30. profit_SubMenu = input("Input value cannot be equal or less than 0. Please re-enter a number 1 to 4: ")
  31. continue
  32. if not profit_SubMenu <= 4:
  33. profit_SubMenu = input("Input value cannot be greater than 4. Please re-enter a number from 1 to 4: ")
  34. continue
  35.  
  36. if profit_SubMenu == 1:
  37.  
  38. print("------------------------------------------------")
  39. print("TOP PROFITABLE PRODUCTS AND ITS SALE DATA")
  40. year_profit_discount = SalesData [["Profit", "Sales","Product Name","Year"]]
  41. years = SalesData.Year.unique()
  42. years.sort()
  43. #year_profit = year_profit_discount.loc[year_profit_discount["Discount"] != 0]
  44.  
  45. required_input_sub = 1
  46. while required_input_sub == 1:
  47. profit_discount = input ("Please enter a number from 1 to 4 to see detail data: \n [1] The top 5 profitable products that sold the most \n [2] The top 5 profitable products that sold the least \n [3] Main menu \n [4] Go back \n Please enter here: ")
  48.  
  49. if profit_discount == "1":
  50. for SalesYear in years:
  51. year_profit = year_profit_discount.loc[year_profit_discount["Year"] == SalesYear]
  52. year_total_profit = year_profit.groupby(by = ["Product Name","Year"]).sum().sort_values(by = "Profit").sort_values(by = "Sales", ascending = False )
  53. print("The top 5 profitable products that sold the most in " + str(SalesYear) + " are: ")
  54. year_total_profit = year_total_profit.reset_index()
  55. print(year_total_profit.head(5))
  56. print(Decorating)
  57.  
  58. if profit_discount == "2":
  59. for SalesYear in years:
  60. year_profit = year_profit_discount.loc[year_profit_discount["Year"] == SalesYear]
  61. year_total_profit = year_profit.groupby(by = ["Product Name", "Year"]).sum().sort_values(by = ["Profit", "Sales"], ascending = False)
  62. print("The top 5 profitable products that sold the least in " + str(SalesYear) + " are: ")
  63. year_total_profit = year_total_profit.reset_index()
  64. print(year_total_profit.head(5))
  65. print(Decorating)
  66.  
  67. if profit_discount == "3":
  68. required_input_sub = 0
  69.  
  70. profit_SubMenu = 3
  71. break
  72. if profit_discount == "4":
  73. required_input_sub = 0
  74. break
  75.  
  76. if profit_SubMenu ==2:
  77.  
  78. print("-------------------------------------------")
  79. print("LEAST PROFITABLE PRODUCTS AND ITS SALE DATA")
  80. year_profit_wdiscount = SalesData [["Year", "Product Name", "Profit", "Sales"]]
  81. years = SalesData.Year.unique()
  82. years.sort()
  83. #year_profit = year_profit_wdiscount.loc[year_profit_wdiscount["Discount"] == 0]
  84.  
  85. required_input_sub = 1
  86. while required_input_sub == 1:
  87. profit_noDiscount = input ("Please enter a number from 1 to 4 to see detail data: \n [1] The least 5 profitable products that sold the most \n [2] The least 5 profitable products that sold the least \n [3] Main menu \n [4] Go back \n Please enter here: ")
  88.  
  89. if profit_noDiscount == "1":
  90. for SalesYear in years:
  91. year_profit = year_profit_wdiscount.loc[year_profit_wdiscount["Year"] == SalesYear]
  92. year_total_profit = year_profit.groupby(by = ["Product Name", "Year"]).sum().sort_values(by = ["Profit", "Sales"], ascending = False)
  93. print("The least 5 profitable products that sold the most in " + str(SalesYear) + " are: ")
  94. year_total_profit = year_total_profit.reset_index()
  95. print(year_total_profit.tail(5))
  96. print(Decorating)
  97.  
  98. if profit_noDiscount == "2":
  99. for SalesYear in years:
  100. year_profit = year_profit_wdiscount.loc[year_profit_wdiscount["Year"] == SalesYear]
  101. year_total_profit = year_profit.groupby(by = ["Product Name", "Year"]).sum().sort_values(by = "Profit").sort_values(by = "Sales", ascending = False)
  102. print("The least 5 profitable products that sold the least in " + str(SalesYear) + " are: ")
  103. year_total_profit = year_total_profit.reset_index()
  104. print(year_total_profit.tail(5))
  105. print(Decorating)
  106.  
  107. if profit_noDiscount == "3":
  108. required_input_sub = 0
  109.  
  110. profit_SubMenu = 3
  111. break
  112. if profit_noDiscount == "4":
  113. required_input_sub = 0
  114. break
  115.  
  116. if profit_SubMenu == 3:
  117.  
  118. break
RAW Paste Data