Skip to content
Spotify Music Data
This dataset consists of ~600 songs that were in the top songs of the year from 2010 to 2019 (as measured by Billboard). You can explore interesting song data pulled from Spotify such as the beats per minute, amount of spoken words, loudness, and energy of every song.
Not sure where to begin? Scroll to the bottom to find challenges!
import pandas as pd
pd.read_csv("spotify_top_music.csv", index_col=0)
Data dictionary
Variable | Explanation | |
---|---|---|
0 | title | The title of the song |
1 | artist | The artist of the song |
2 | top genre | The genre of the song |
3 | year | The year the song was in the Billboard |
4 | bpm | Beats per minute: the tempo of the song |
5 | nrgy | The energy of the song: higher values mean more energetic (fast, loud) |
6 | dnce | The danceability of the song: higher values mean it's easier to dance to |
7 | dB | Decibel: the loudness of the song |
8 | live | Liveness: likeliness the song was recorded with a live audience |
9 | val | Valence: higher values mean a more positive sound (happy, cheerful) |
10 | dur | The duration of the song |
11 | acous | The acousticness of the song: likeliness the song is acoustic |
12 | spch | Speechines: higher values mean more spoken words |
13 | pop | Popularity: higher values mean more popular |
Source of dataset.
import pandas as pd from sqlalchemy import create_engine
Read the CSV file into a pandas dataframe
df = pd.read_csv("spotify_top_music.csv")
Create a connection to the database
engine = create_engine('postgresql://username:password@localhost:5432/database_name')
Write the dataframe to the database table
df.to_sql('table_name', engine, if_exists='replace')
import pandas as pd
from sqlalchemy import create_engine
import psycopg2
# Read the CSV file into a pandas dataframe
df = pd.read_csv("spotify_top_music.csv")
# Create a connection to the database
try:
engine = create_engine('postgresql://gusflores:abril1320@localhost:5432/spotify')
conn = engine.connect()
print("Connection established successfully!")
except psycopg2.OperationalError as e:
print(f"Error: {e}")
# Write the dataframe to the database table
try:
df.to_sql('table_name', engine, if_exists='replace')
print("Data written to PostgreSQL successfully!")
except Exception as e:
print(f"Error: {e}")
finally:
conn.close()