Skip to content

Instantly share code, notes, and snippets.

@edivandecastro
Created January 9, 2024 20:11
Show Gist options
  • Save edivandecastro/0bad924781aad2207b2ad86ff487ac6c to your computer and use it in GitHub Desktop.
Save edivandecastro/0bad924781aad2207b2ad86ff487ac6c to your computer and use it in GitHub Desktop.
import pandas as pd
df = pd.read_csv('./music_project.csv', names=['userID', 'Track', 'artist', 'genre', 'City', 'time', 'Day'])
amount_music_group = {}
# Contando as músicas tocadas em cada cidade
for indice, linha in df.iterrows():
city_name = linha['City']
if indice != 0:
if city_name in amount_music_group:
amount_music_group[city_name] += 1
else:
amount_music_group[city_name] = 1
print(amount_music_group)
data = {}
# Agrupando a quantidade de música tocada por dia e por cidade
for indice, linha in df.iterrows():
city_name = linha['City']
day_name = linha['Day']
if indice != 0:
if city_name in data:
data[city_name][day_name] += 1
else:
data[city_name] = { 'Monday': 0, 'Wednesday': 0, 'Friday': 0 }
data[city_name][day_name] += 1
print(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment