Last active
December 11, 2023 19:44
-
-
Save MartinWeiss12/ef63c583ec1b9e61ba1560db2983eb64 to your computer and use it in GitHub Desktop.
Convert UTC to desired timezone
This file contains 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
timezone = pytz.timezone('US/Eastern') | |
datetime.now(tz=timezone) | |
filtered_data['ts'] = pd.to_datetime(filtered_data['ts'], utc=True) | |
filtered_data['ts'] = filtered_data['ts'].dt.tz_convert(timezone) | |
filtered_data['ts'] = filtered_data['ts'].dt.strftime('%Y-%m-%d %H:%M:%S') | |
# filter FROM a date | |
# start_date = '2020-01-01' | |
# filtered_data = filtered_data[filtered_data['ts'] >= start_date] | |
# filter TO a date | |
# end_date = '2022-01-01' | |
# filtered_data = filtered_data[filtered_data['ts'] <= end_date] | |
streaming_log = filtered_data[['ts', 'master_metadata_track_name', 'master_metadata_album_album_name', | |
'master_metadata_album_artist_name', 'spotify_track_uri']] | |
streaming_log.columns = ['Timestamp', 'Track', 'Album', 'Artist', 'URI'] | |
streaming_log = streaming_log.sort_values('Timestamp') | |
ts_list = streaming_log['Timestamp'].tolist() | |
track_list = streaming_log['Track'].tolist() | |
uri_list = streaming_log['URI'].tolist() | |
streaming_log = streaming_log.drop(columns=['URI'], axis=1) | |
streaming_log.to_excel(f'{output_path}spotify-streaming-log.xlsx', index=False) | |
print('Minutes Played: {:,}'.format(filtered_data['ms_played'].sum() // 60000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment