Created
August 4, 2018 12:09
-
-
Save patricoferris/ff2abcd957c2cab6847631869aa605a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Connecting to the Kaggle Pitchfork Database | |
import sqlite3 as sql | |
import numpy as np | |
db = sql.connect('../../data/pitchfork.sqlite') | |
cursor = db.cursor() | |
artist_dict = {} | |
artist_lookup = {} | |
#An artist class for holding the information | |
class Artist: | |
def __init__(self, name): | |
self.name = name | |
self.reviews = [] | |
self.genres = [] | |
self.scores = [] | |
def add_review(self, review): | |
self.reviews.append(review) | |
def add_genre(self, genre): | |
self.genres.append(genre) | |
def add_score(self, score): | |
self.scores.append(score) | |
def __str__(self): | |
return self.name | |
#Reading in the data and storing it as Aritst objects in our dictionary | |
cursor.execute('select reviews.reviewid, artist, genre, score from reviews join genres on genres.reviewid = reviews.reviewid') | |
for row in cursor: | |
if row[1] not in artist_dict: | |
artist_dict[row[1]] = Artist(row[1]) | |
artist_dict[row[1]].add_review(row[0]) | |
artist_dict[row[1]].add_genre(row[2]) | |
artist_dict[row[1]].add_score(row[3]) | |
artist_lookup[row[1]] = len(artist_lookup) | |
else: | |
artist_dict[row[1]].add_review(row[0]) | |
artist_dict[row[1]].add_genre(row[2]) | |
artist_dict[row[1]].add_score(row[3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment