# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3.9.7 64-bit
#     name: python3
# ---

# Imports
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler

df = pd.read_csv("songs.csv")

df = df[["Context", "tempo", "danceability", "energy", "loudness", "speechiness", "acousticness", "instrumentalness", "liveness", "valence"]]
df.Context = df.Context.astype("category")
grouped = df.groupby(df.Context)
df_walking = grouped.get_group("Walking")
df_studying = grouped.get_group("Studying")

min_max = MinMaxScaler()
df_studying.loc[:, "tempo":] = min_max.fit_transform(df_studying.loc[:, "tempo":])
df_walking.loc[:, "tempo":] = min_max.fit_transform(df_walking.loc[:, "tempo":])

df_studying = df_studying.drop("Context", 1)
df_walking = df_walking.drop("Context", 1)

labels = list(df_studying)[:]
features_studying = df_studying.mean().tolist()
features_walking = df_walking.mean().tolist()
angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False).tolist()
features_studying += features_studying[:1]
features_walking += features_walking[:1]
angles += angles[:1]

# +
fig = plt.figure(figsize=(20,20))
ax = fig.add_subplot(221, polar=True)
ax.plot(angles, features_studying, 'o-', linewidth=2, label = "Studying", color= 'blue')
ax.fill(angles, features_studying, alpha=0.25, facecolor='blue')

ax.plot(angles, features_walking, 'o-', linewidth=2, label = "Walking", color= 'orange')
ax.fill(angles, features_walking, alpha=0.25, facecolor='orange')
ax.set_title("Analysis of Mean Values of Music Features")

plt.xticks(angles[:-1], labels)

# lol

plt.yticks([0.1 , 0.2 , 0.3 , 0.4, 0.5,  0.6, 0.7, 0.8], ["0.1",'0.2', "0.3", "0.4", "0.5", "0.6", '0.7', '0.8'], size=9)
plt.ylim(0,0.8)
plt.legend(loc='best', bbox_to_anchor=(0.1, 0.1))

plt.show()

StarcoderdataJupyterScriptsDedupFiltered