Skip to content

Instantly share code, notes, and snippets.

View pragyy's full-sized avatar
🏠
Working from home

Pragya Verma pragyy

🏠
Working from home
View GitHub Profile
@pragyy
pragyy / delete_columns.py
Last active May 30, 2021 16:53
Import packages and CSV file in python
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' ])
# 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')
# 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)
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