Advertisement
nein_yards

CustomerFeedbackProcessing

Dec 12th, 2020 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. # IMPORTING PACKAGES
  2. import numpy as np
  3. import pandas as pd
  4. import matplotlib.pyplot as plt
  5. import matplotlib.dates as mdates
  6. import datetime
  7.  
  8. customer_feedback_tuples = []
  9. customer_feedback_def = [('bill-id', 'i4'),
  10. ('date', 'M8[us]'),
  11. ('ambience', 'i4'),
  12. ('service', 'i4'),
  13. ('food', 'i4'),
  14. ('hygiene', 'i4')]
  15.  
  16. # CREATING FOR LOOP TO TAKE INPUT FROM CUSTOMERS
  17. menu_exit = False
  18. while not menu_exit:
  19. print('-' * 100)
  20. print("* Welcome to Cloud Akali! *")
  21. print("please follow the instructions below to complete the customer survey and rate out of 10! ")
  22. bill_id = int(input("Enter bill id: "))
  23. visit_date = datetime.datetime.strptime(
  24. input('Enter date of visit (dd/mm/yyyy): '),
  25. '%d/%m/%Y'
  26. )
  27. ambience_rating = int(input('How did you like the overall ambience of the restaurant?: '))
  28. service_rating = int(input("How would you rate our service?: "))
  29. food_rating = int(input("What did you think about our food?: "))
  30. hygiene_rating = int(input('Did our restaurant meet your standard of cleanliness and hygiene?: '))
  31. customer_feedback_tuples.append((bill_id,
  32. visit_date,
  33. ambience_rating,
  34. service_rating,
  35. food_rating,
  36. hygiene_rating))
  37. menu_exit = input('Type "yes" to proceed: ').lower() != 'yes'
  38. print('-' * 100)
  39.  
  40. # example_data = [(1, '2017-01-01', 2, 4, 3, 3), (11, '2018-04-14', 10, 8, 6, 6), (21, '2015-03-30', 4, 7, 7, 8), (31, '2015-12-24', 9, 9, 7, 3), (41, '2020-04-13', 5, 1, 2, 8), (51, '2015-03-29', 3, 5, 10, 9), (61, '2016-05-28', 9, 7, 7, 7), (71, '2018-02-05', 4, 4, 3, 2), (81, '2015-05-02', 7, 9, 7, 6), (91, '2014-05-26', 10, 4, 3, 6), (101, '2019-07-02', 4, 7, 1, 4), (111, '2016-01-01', 6, 10, 9, 3), (121, '2019-02-10', 2, 4, 8, 5), (131, '2017-04-13', 7, 1, 10, 9), (141, '2018-09-01', 3, 4, 5, 8), (151, '2020-02-13', 10, 4, 3, 6), (161, '2017-02-05', 8, 8, 2, 7), (171, '2016-02-17', 1, 9, 9, 2), (181, '2020-06-06', 9, 6, 8, 5), (191, '2017-11-23', 3, 3, 2, 1), (201, '2019-01-03', 7, 1, 2, 3), (211, '2020-07-12', 6, 5, 8, 1), (221, '2015-10-05', 10, 10, 2, 3), (231, '2020-07-01', 3, 1, 3, 4)]
  41. # customer_feedback_tuples = example_data
  42.  
  43. customer_feedback = np.array(customer_feedback_tuples, dtype=customer_feedback_def)
  44. customer_feedback = np.sort(customer_feedback, order='date') # sorting by date
  45.  
  46. df = pd.DataFrame(customer_feedback).set_index('bill-id')
  47. df.to_csv('csvCA.csv')
  48. print(df)
  49.  
  50. years = mdates.YearLocator() # every year
  51. months = mdates.MonthLocator() # every month
  52. years_fmt = mdates.DateFormatter('%Y')
  53.  
  54. fig, ax = plt.subplots()
  55. ax.plot('date', 'ambience', color='red', data=customer_feedback, label='Ambience')
  56. ax.plot('date', 'service', color='blue', data=customer_feedback, label='Service')
  57. ax.plot('date', 'food', color='yellow', data=customer_feedback, label='Food')
  58. ax.plot('date', 'hygiene', color='green', data=customer_feedback, label='Hygiene')
  59.  
  60. ax.xaxis.set_major_locator(years)
  61. ax.xaxis.set_major_formatter(years_fmt)
  62. ax.xaxis.set_minor_locator(months)
  63.  
  64. datemin = np.datetime64(customer_feedback['date'][0], 'Y')
  65. datemax = np.datetime64(customer_feedback['date'][-1], 'Y') + np.timedelta64(1, 'Y')
  66. ax.set_xlim(datemin, datemax)
  67.  
  68. ax.format_xdata = mdates.DateFormatter('%Y-%m-%d')
  69. ax.grid(True)
  70. plt.ylim(0, 10)
  71. fig.autofmt_xdate()
  72. plt.xlabel('Year')
  73. plt.ylabel('Score')
  74.  
  75. plt.legend()
  76. plt.show()
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement