-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbpm_mean_stdev
41 lines (31 loc) · 907 Bytes
/
bpm_mean_stdev
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
import music
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import plotly.express as px
#link between a song's genre and its key + bpm
m = music.get_music()
d = {}
for i in m:
genre = i['artist']['terms']
bpm = i['song']['tempo']
if bpm == 0:
continue
elif genre in d:
d[genre].append(bpm)
else:
d[genre] = [bpm]
new_d = {}
for g in d:
if len(d[g]) >= 131:
new_d[g] = d[g]
for g in new_d:
# Currently, executing this code will create a graph of the mean BPM by genre.
# To create a graph of St. Dev. of BPM by genre, use np.std instead of np.mean in line 32.
new_d[g] = np.mean(new_d[g])
k = list(new_d.keys())
v = list(new_d.values())
print(len(new_d))
plt.bar(k, v, color = ['black', 'brown', 'purple', 'blue', 'cyan', 'orange', 'red', 'yellow', 'violet', 'green'])
plt.xticks(rotation = 60)
plt.show()