You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.7 KiB

6 years ago
  1. import numpy as np
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4. from datetime import datetime, date, timedelta
  5. products = pd.read_csv('datasets/fairMarket-products.csv')
  6. print products.tail(1)
  7. #generate the full set of days from the first date to the last in the dataset
  8. months = []
  9. days = []
  10. dInit = date(2015, 5, 04)
  11. dEnd = date(2017, 8, 31)
  12. delta = dEnd - dInit
  13. for i in range(delta.days+1):
  14. day = dInit + timedelta(days=i)
  15. dayString = day.strftime("%d/%m/%y")
  16. dayDatetime = datetime.strptime(dayString, '%d/%m/%y')
  17. days.append(dayDatetime)
  18. #add the dates of products creation to the days array
  19. for productDate in products['Creado en']:
  20. if isinstance(productDate, basestring):
  21. productDay = str.split(productDate)[0]
  22. productDayDatetime = datetime.strptime(productDay, '%d/%m/%y')
  23. days.append(productDayDatetime)
  24. #count days frequency in days array
  25. unique, counts = np.unique(days, return_counts=True)
  26. countDays = dict(zip(unique, counts))
  27. realCounts = []
  28. for count in counts:
  29. realCounts.append(count-1)
  30. #count the total acumulation of products created in each days
  31. totalCount = 0
  32. globalCount = []
  33. for k in realCounts:
  34. totalCount = totalCount + k
  35. globalCount.append(totalCount)
  36. dates = countDays.values()
  37. counts = countDays.values()
  38. #plot the data
  39. plt.title("New products published each day")
  40. plt.plot(unique, realCounts)
  41. plt.show()
  42. plt.title("Total products in FairMarket each day")
  43. plt.plot(unique, globalCount)
  44. plt.show()
  45. plt.title("New products and total products each day")
  46. plt.plot(unique, realCounts, label="new products offered each day")
  47. plt.plot(unique, globalCount, label="total products in FairMarket each day")
  48. plt.legend(loc='upper left')
  49. plt.show()