Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add my version in Python #216

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions spotify_data_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import csv
import os

# Load Spotify data from the CSV file
def load_data(filename):
with open(filename, mode='r', encoding='latin1') as file:
reader = csv.DictReader(file)
return list(reader)

# Challenge 1: Identify the number of songs in the file
def total_songs(data):
return len(data)

# Challenge 2: Identify the number of songs in the key of E
def songs_in_key_e(data):
count = 0
for row in data:
if row['key'] == 'E':
count += 1
return count

# Challenge 3: Count the occurrences of values in a specified column (artist names)
def most_common_artist(data):
artist_count = {}
for row in data:
artist = row['artist(s)_name']
if artist in artist_count:
artist_count[artist] += 1
else:
artist_count[artist] = 1
return max(artist_count, key=artist_count.get)

if __name__ == "__main__":
# Create a folder for your project with your github handle
folder_name = "your_github_handle"
if not os.path.exists(folder_name):
os.makedirs(folder_name)

# Load data
data = load_data('spotify-2023.csv')

# Perform challenges
print(f"Total number of songs: {total_songs(data)}")
print(f"Number of songs in the key of E: {songs_in_key_e(data)}")
print(f"The most common artist is: {most_common_artist(data)}")