Advertisement
Vitaliy_Novichikhin

8.5.2 Верно!!!

Feb 14th, 2022
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. import pandas
  2. import seaborn
  3.  
  4. data = pandas.read_csv('support_data.csv')
  5.  
  6. segments_old = ['Segment 0', 'Segment 1', 'Segment 2']
  7. segments_new = ['Потенциальные клиенты', 'Обычные клиенты', 'VIP-клиенты']
  8. intervals = ['До внедрения роботов', 'После внедрения роботов']
  9.  
  10. intervals_column = list(data['interval'])
  11. segments_column = list(data['segment'])
  12. duration_column = list(data['duration'])
  13. #print(duration_column[:10])
  14. mean_duration = []
  15.  
  16. # ваш код здесь
  17. for segment in segments_old:
  18.     interval_duration = []
  19.     # вложенный цикл по двум периодам
  20.     for interval in intervals:
  21.         score = 0
  22.         counter = 0
  23.         # вложенный цикл по строкам
  24.         for index in range(len(data)):
  25.             if (segments_column[index] == segment and
  26.                 intervals_column[index] == interval):
  27.                 score += duration_column[index]
  28.                 counter += 1
  29.         print(score, counter)
  30.         interval_duration.append(score / counter)
  31.     print(interval_duration)
  32.     mean_duration.append(interval_duration)
  33.  
  34. seaborn.heatmap(mean_duration, xticklabels=intervals, yticklabels=segments_new, annot=True, cmap='RdYlGn')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement