application_vnd.jupyter.stderr_output_1.png
import pandas as pd

spotify = pd.read_csv('C:\\Users\\KK\\Documents\\Kitu\\College\\Senior Year\\Extracurriculars\\Python\\Spotify\\.spyproject\\data.csv')

spotify.shape
spotify.dtypes

spotify.Region = spotify.Region.astype('category')
spotify.Date = pd.to_datetime(spotify['Date'])
spotify.dtypes

globe = spotify[spotify.Region == 'global']
usa = spotify[spotify.Region == 'us']
great_britain = spotify[spotify.Region == 'gb']
mexico = spotify[spotify.Region == 'mx']
taiwan = spotify[spotify.Region == 'tw']
singapore = spotify[spotify.Region == 'sg']

top_globe = globe.groupby('Track Name').agg({'Streams': 'sum'})
top_globe = top_globe.sort_values(['Streams'], ascending=False)
top_globe['country'] = 'Globe'
top_usa = usa.groupby('Track Name').agg({'Streams': 'sum'})
top_usa = top_usa.sort_values(['Streams'], ascending=False)
top_usa['country'] = 'USA'
top_great_britain = great_britain.groupby('Track Name').agg({'Streams': 'sum'})
top_great_britain = top_great_britain.sort_values(['Streams'], ascending=False)
top_great_britain['country'] = 'Great Britain'
top_mexico = mexico.groupby('Track Name').agg({'Streams': 'sum'})
top_mexico = top_mexico.sort_values(['Streams'], ascending=False)
top_mexico['country'] = 'Mexico'
top_taiwan = taiwan.groupby('Track Name').agg({'Streams': 'sum'})
top_taiwan = top_taiwan.sort_values(['Streams'], ascending=False)
top_taiwan['country'] = 'Taiwan'
top_singapore = singapore.groupby('Track Name').agg({'Streams': 'sum'})
top_singapore = top_singapore.sort_values(['Streams'], ascending=False)
top_singapore['country'] = 'Singapore'

top_globe = top_globe[0:3]
top_usa = top_usa[0:3]
top_great_britain = top_great_britain[0:3]
top_mexico = top_mexico[0:3]
top_taiwan = top_taiwan[0:3]
top_singapore = top_singapore[0:3]

top_all_merged = top_globe.append([top_usa, top_great_britain, top_mexico, top_taiwan, top_singapore])

top_all_merged = top_all_merged.reset_index()

all_songs = top_all_merged['Track Name'].value_counts()
all_songs = all_songs.reset_index()
len(top_all_merged['Track Name'].value_counts())