-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathspotify.py
45 lines (41 loc) · 1.08 KB
/
spotify.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
from sqlite3.dbapi2 import connect
import pandas as pd
import sqlite3 as sq3
import csv
df = pd.read_csv(r"model_ready_data_no_dupes.csv")
df.rename(columns={'Unnamed: 0': 'id'}, inplace=True)
#df.drop(index=0, axis=0, inplace=True)
#df.drop(columns=['Unnamed: 0'], inplace=True)
print(df.columns)
conn = sq3.connect("spotify.sqlite3")
curs = conn.cursor()
curs.execute("""CREATE TABLE IF NOT EXISTS spotify (
id INT,
name TEXT,
duration_ms FLOAT,
explicit INT,
artists TEXT,
release_date DATETIME,
danceability FLOAT,
energy FLOAT,
key FLOAT,
loudness FLOAT,
mode FLOAT,
speechiness FLOAT,
acousticness FLOAT,
instrumentalness FLOAT,
liveness FLOAT,
valence FLOAT,
tempo FLOAT,
time_signature FLOAT,
popularity FLOAT
);""")
conn.commit()
df.to_sql('spotify', conn, if_exists='replace', index=False)
curs.execute("""
SELECT COUNT(*) FROM spotify;
""").fetchall()
query = curs.execute("""
select name, artists, danceability from spotify
where danceability > 0.8
""").fetchall()