-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbite130 Analyze Data on JSON.py
66 lines (37 loc) · 1.35 KB
/
bite130 Analyze Data on JSON.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from collections import Counter
import requests
CAR_DATA = 'https://bites-data.s3.us-east-2.amazonaws.com/cars.json'
# pre-work: load JSON data into program
with requests.Session() as s:
data = s.get(CAR_DATA).json() #data is a list of dictionaries
#print(data)
def most_prolific_automaker(year):
automakers = [dictionaries['automaker'] for dictionaries in data if dictionaries['year'] == year]
automaker_count = Counter(automakers)
#return automaker_cou
name, count = automaker_count.most_common(1)[0]
return name
#return most_common_automaker()
'''
for dictionaries in data:
if 'year' in dictionaries and dictionaries['year'] == year:
automakers.append(dictionaries['automaker'])
'''
#return automakers
# return automaker_count
#
print(most_prolific_automaker(1993))
'''
automaker_totals_list = [item['automaker'] for item in data]
'''
# print(automaker_totals_list)
#print(most_common_automaker)
# your turn:
def most_prolific_automaker(year):
"""Given year 'year' return the automaker that released
the highest number of new car models"""
pass
def get_models(automaker, year):
"""Filter cars 'data' by 'automaker' and 'year',
return a set of models (a 'set' to avoid duplicate models)"""
pass