This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| df1 = df1.drop(columns=['Unnamed: 0', 'name', 'endTime', 'type', 'uri', 'track_href', 'analysis_url', 'duration_ms' ]) | |
| df2 = df2.drop(columns=['Unnamed: 0', 'id', 'spotify_id', 'list_id' ]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # we are keeping the last instance instead of the first as we need the latest entry of the song | |
| df1 = df1.drop_duplicates( subset = 'trackName', keep = 'last') | |
| df2 = df2.drop_duplicates( subset = 'song_name', keep = 'last') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # converting ms to minute and extracting date from datetime column | |
| my_streaming['mins_played'] = my_streaming.apply(lambda x: round(x['msPlayed']/60000,2), axis=1) | |
| my_streaming['date'] = my_streaming.apply(lambda x: pd.to_datetime(x['datetime'][:10],format='%Y-%m-%d'),axis=1) | |
| # calculate the daily streaming time length | |
| daily_length = my_streaming.groupby('date',as_index=True).sum() | |
| # create new date series for displaying time series data | |
| idx = pd.DataFrame(pd.date_range(min(my_streaming.date), max(my_streaming.date)),columns=['date']) | |
| idx['date'] = idx.apply(lambda x: pd.to_datetime(x['date'],format='%Y-%m-%d'),axis=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def plot_radar(idx,color): | |
| # categories | |
| category = ['energy', 'danceability', 'valence', 'liveness', 'acousticness'] | |
| N = len(category) | |
| #values | |
| values = radar.iloc[idx].to_list() | |
| values += values[:1] | |
| # calculate angle for each category |