-
Notifications
You must be signed in to change notification settings - Fork 162
/
solution.py
47 lines (38 loc) · 1.14 KB
/
solution.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
# import module
import pandas as pd
def count_songs_with_key(data):
counts = data['key'].value_counts()['E']
return counts
def count_occurences_of_values(data):
dict = {}
artists = data['artist(s)_name']
for artist in artists:
name = ""
for x in artist:
if x != ',':
name+=x
else:
name = name.strip()
if dict.get(name) == None:
dict[name] = 1
else:
dict[name] = dict[name] + 1
name=""
name = name.strip()
if dict.get(name) == None:
dict[name] = 1
else:
dict[name] = dict[name] + 1
keyMax = max(zip(dict.values(), dict.keys()))[1]
return(keyMax)
# read the csv file
results = pd.read_csv('spotify-2023.csv')
# solution 1
numOfSongs = len(results)
print("Number of songs: ", numOfSongs)
# solution 2
numOfSongsWithE = count_songs_with_key(results)
print("Number of songs with key E: ", numOfSongsWithE)
# solution 3
mostOccurences = count_occurences_of_values(results)
print("Most streamed artist: ", mostOccurences)