-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.py
More file actions
23 lines (18 loc) · 778 Bytes
/
Copy pathreport.py
File metadata and controls
23 lines (18 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def generate_average_rating_report(data):
brand_ratings = {}
# Собираем все рейтинги по брендам
for row in data:
brand = row['brand']
rating = float(row['rating'])
if brand not in brand_ratings:
brand_ratings[brand] = {'total_rating': 0, 'count': 0}
brand_ratings[brand]['total_rating'] += rating
brand_ratings[brand]['count'] += 1
# Вычисляем средние значения
report_data = [
(brand, round(info['total_rating'] / info['count'], 2))
for brand, info in brand_ratings.items()
]
# Сортируем по рейтингу
report_data.sort(key=lambda x: x[1], reverse=True)
return report_data