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

Added Python code. #215

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions submissions/Dhairya-A-Mehra/Result.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Total number of songs in the file: 953
Number of songs in the key of E: 62
Most common artist name: Taylor Swift
35 changes: 35 additions & 0 deletions submissions/Dhairya-A-Mehra/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import csv
from collections import Counter

# Define the filename for the Spotify CSV data
filename = 'spotify-2023.csv'

# Read and analyze the CSV file
with open(filename, 'r') as csvfile:
csvreader = csv.reader(csvfile)

# Extract the header fields from the file
header = next(csvreader)

# Initialize data containers
data_rows = [] # Store all data rows
artist_names = [] # Store artist names for analysis

# Iterate through the CSV data
for row in csvreader:
data_rows.append(row)

# Extract and record artist names
artist_name = row[header.index('artist(s)_name')]
artist_names.append(artist_name)

# Count the number of songs in the key of 'E'
songs_in_key_E = sum(1 for row in data_rows if row[header.index('key')] == 'E')

# Determine the most frequently occurring artist name
most_common_artist_name = max(Counter(artist_names).keys(), key=lambda k: Counter(artist_names)[k])

# Output the results
print(f'Total number of songs in the file: {len(data_rows)}')
print(f'Number of songs in the key of E: {songs_in_key_E}')
print(f'Most common artist name: {most_common_artist_name}')
Loading