Rolling Stones Lab
Getting Started
In this exercise, we will be using data from the top 500 rolling stone albums
. We have this data contained in the data.csv
file. We will be building out the following functions to answer questions and interact with this data.
remember: reading from a csv file in python looks like the following:
import csv
with open(file_name) as f:
# we are using DictReader because we want our information to be in dictionary format.
reader = csv.DictReader(f)
# some more code
Once we have our reader
reading our file as dictionaries, we want our data to be a list of dictionaries. So, we need to loop through our reader
and create a list. *hint: list comprehension / for loops are your friend"
# our data will look something like this once we have read it and turned it into a list of `OrderedDict`s
# don't worry, the ordered dicts look different but we can interact with them the same way we do normal dicts
[OrderedDict([('number', '1'), ('year', '1967'), ('album', "Sgt. Pepper's Lonely Hearts Club Band"), ('artist', 'The Beatles'), ('genre', 'Rock'), ('subgenre', 'Rock & Roll, Psychedelic Rock')]), OrderedDict([('number', '2'), ('year', '1966'), ('album', 'Pet Sounds'), ('artist', 'The Beach Boys'), ('genre', 'Rock'), ('subgenre', 'Pop Rock, Psychedelic Rock')]), OrderedDict([('number', '3'), ('year', '1966'), ('album', 'Revolver'), ('artist', 'The Beatles'), ('genre', 'Rock'), ('subgenre', 'Psychedelic Rock, Pop Rock')])]
After we have our data formated the way we want it, we can now begin working on defining our functions.
Functions to build-out:
Each of the following functions can be defined in the functions.py
file.
- Searching functions
- Find by name - Takes in a string that represents the name of an album. Should return a dictionary with the correct album, or return
None
. - Find by rank - Takes in a number that represents the rank in the list of top albums and returns the album with that rank. If there is no album with that rank, it returns
None
. - Find by year - Takes in a number for the year in which an album was released and returns a list of albums that were released in that year. If there are no albums released in the given year, it returns an empty list.
- Find by years - Takes in a start year and end year. Returns a list of all albums that were released on or between the start and end years. If no albums are found for those years, then an empty list is returned.
- Find by ranks - Takes in a start rank and end rank. Returns a list of albums that are ranked between the start and end ranks. If no albums are found for those ranks, then an empty list is returned.
- Find by name - Takes in a string that represents the name of an album. Should return a dictionary with the correct album, or return
- All functions
- All titles - Returns a list of titles for each album.
- All artists - Returns a list of artist names for each album.
- Questions to answer / functions
- Artists with the most albums - Returns the artist with the highest amount of albums on the list of top albums
- Most popular word - Returns the word used most in amongst all album titles
- Histogram of albums by decade - Returns a histogram with each decade pointing to the number of albums released during that decade.
- Histogram by genre - Returns a histogram with each genre pointing to the number of albums that are categorized as being in that genre.