-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze.py
60 lines (53 loc) · 2.06 KB
/
analyze.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
# Analyze existing output.h5
from tables import *
import numpy as np
class Track(IsDescription):
song = StringCol(128)
album = StringCol(128)
danceability = Float32Col()
loudness = Float32Col()
acousticness = Float32Col()
instrumentalness = Float32Col()
liveness = Float32Col()
energy = Float32Col()
speechiness = Float32Col()
valence = Float32Col()
tempo = Float32Col()
key = Int32Col()
mode = StringCol(5)
h5file = open_file('output.h5', mode='r', title='Spotify Tracks')
danceability = np.array([])
acousticness = np.array([])
energy = np.array([])
valence = np.array([])
tempo = np.array([])
for table in h5file.root.trackinfo:
for track in table:
danceability = np.append(danceability, track['danceability'])
acousticness = np.append(acousticness, track['acousticness'])
energy = np.append(energy, track['energy'])
valence = np.append(valence, track['valence'])
tempo = np.append(tempo, track['tempo'])
print('Average values for ' + table.name + ':')
print(' Valence:')
print(' Mean: ' + str(np.mean(valence)))
print(' Median: ' + str(np.median(valence)))
print(' Standard Deviation: ' + str(np.std(valence)))
print(' Danceability:')
print(' Mean: ' + str(np.mean(danceability)))
print(' Median: ' + str(np.median(danceability)))
print(' Standard Deviation: ' + str(np.std(danceability)))
print(' Acousticness:')
print(' Mean: ' + str(np.mean(acousticness)))
print(' Median: ' + str(np.median(acousticness)))
print(' Standard Deviation: ' + str(np.std(acousticness)))
print(' Energy:')
print(' Mean: ' + str(np.mean(energy)))
print(' Median: ' + str(np.median(energy)))
print(' Standard Deviation: ' + str(np.std(energy)))
print(' Tempo:')
print(' Mean: ' + str(np.mean(tempo)))
print(' Median: ' + str(np.median(tempo)))
print(' Standard Deviation: ' + str(np.std(tempo)))
print()
h5file.close()