Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 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","Product Name","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 = ["Product Name","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", "Product Name", "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 = ["Product Name", "Year"]).sum().sort_values(by = ["Profit", "Sales"], ascending= True)
  46. print("The top 10 profitable products with discount that sold the least in " + str(SalesYear) + " are: ")
  47. year_total_profit = year_total_profit.reset_index()
  48. print(year_total_profit.tail(10))
  49.  
  50.  
  51.  
  52. print("Least profitable products that sold Without Discount")
  53. print("---------------------------------")
  54. year_profit_wdiscount = SalesData [["Year", "Product Name", "Sales", "Discount", "Profit"]]
  55. years = SalesData.Year.unique()
  56. for SalesYear in years:
  57. year_profit = year_profit_discount.loc[year_profit_discount["Discount"] == 0]
  58. year_profit = year_profit_wdiscount.loc[year_profit_wdiscount["Year"] == SalesYear]
  59. year_total_profit = year_profit.groupby(by = ["Product Name", "Year"]).sum().sort_values(by = ["Profit", "Sales"], ascending = True)
  60. print("The least 10 profitable products without discount that sold the most in " + str(SalesYear) + " are: ")
  61. year_total_profit = year_total_profit.reset_index()
  62. print(year_total_profit.head(10))
  63.  
  64. print("---------------------------------")
  65. year_profit_wdiscount = SalesData [["Year", "Product Name", "Sales", "Discount", "Profit"]]
  66. years = SalesData.Year.unique()
  67. for SalesYear in years:
  68. year_profit = year_profit_discount.loc[year_profit_discount["Discount"] == 0]
  69. year_profit = year_profit_wdiscount.loc[year_profit_wdiscount["Year"] == SalesYear]
  70. year_total_profit = year_profit.groupby(by = ["Product Name", "Year"]).sum().sort_values(by = ["Profit", "Sales"], ascending = False)
  71. print("The least 10 profitable products without discount that sold the least in " + str(SalesYear) + " are: ")
  72. year_total_profit = year_total_profit.reset_index()
  73. print(year_total_profit.tail(10))
  74.  
  75.  
  76. #1, 2, 3, 4 = "2014", "2015", "2016", "2017"
  77. #print(1)
  78. #print(2)
  79. #print(3)
  80. #print(4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement