text_html_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style('darkgrid')

ds = pd.read_csv('/kaggle/input/spotify-datacsv/spotify_data.csv', dtype={'19': float})
ds

ds.isna().sum()

ds.shape

ds.columns

len(ds.columns)

top_ten_genre = ds.groupby('artists').count().sort_values(by='name', ascending=False)['name'][:10]
top_ten_genre

top_ten_genre.plot.barh()

top_loudest_tracks = ds[['loudness', 'artists']].sort_values(by='loudness', ascending=False)[:5]
top_loudest_tracks

top_loudest_tracks.plot.barh()

top_dancable_songs = ds[['danceability', 'artists', 'name']].sort_values(by='danceability', ascending=False)[:5]
top_dancable_songs

top_instrumental_songs = ds[['instrumentalness', 'artists', 'name']].dropna(subset=['artists']).sort_values(by='instrumentalness', ascending=False)[:5]
top_instrumental_songs

interest_feature_cols = ['loudness', 'acousticness', 'danceability', 'duration_ms', 'energy', 'instrumentalness', 'liveness', 'speechiness']

for feature_cols in interest_feature_cols:
    pos_data = ds[ds['mode'] == 1][feature_cols]
    neg_data = ds[ds['mode'] == 0][feature_cols]
    pos_data = pd.melt(pos_data.to_frame(), value_name=f'{feature_cols}_pos')
    neg_data = pd.melt(neg_data.to_frame(), value_name=f'{feature_cols}_neg')
    plt.figure(figsize=(12, 7))
    sns.histplot(data=pos_data, x=f'{feature_cols}_pos', bins=40, color='green', alpha=0.5, label='Positive')
    sns.histplot(data=neg_data, x=f'{feature_cols}_neg', bins=40, color='red', alpha=0.5, label='Negative')
    plt.legend(loc='upper right')
    plt.title(f'Positive and Negative Histogram for {feature_cols}')
    plt.show()