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
| import pandas as pd | |
| import numpy as np | |
| import plotly.express as px | |
| from typing import List, Union | |
| def bin_ages(age_series: pd.Series) -> pd.Series: | |
| age_labels = [f"[{i}, {i+10})" for i in range(0, 91, 10)] | |
| age_bins = pd.IntervalIndex.from_tuples( |
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
| import pandas as pd | |
| import plotly.graph_objects as go | |
| # Load the resulting dataset | |
| data = pd.read_csv("final_data.csv") | |
| # Group by social networks AND gender | |
| gender_socials = data.groupby(by=["Used Social Networks", "Gender"]).count() | |
| # Unstack the genders, leaving only the social networks on the index\ |
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
| import pandas as pd | |
| from matplotlib import pyplot as plt | |
| # Load the resulting dataset | |
| data = pd.read_csv("final_data.csv") | |
| # Group by social networks AND gender | |
| gender_socials = data.groupby(by=["Used Social Networks", "Gender"]).count() | |
| # Unstack the grouped DataFrame and plot it in a bar chart (the genders\ |
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
| import pandas as pd | |
| from typing import List | |
| # Base clode for splitting and unpivoting a Series | |
| # https://stackoverflow.com/questions/19482970/get-list-from-pandas-dataframe-column-headers | |
| def unpivot_delimited_series( | |
| series: pd.Series, | |
| delimiter: str | |
| ) -> pd.DataFrame: |
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
| import pandas as pd | |
| from typing import List | |
| # Base clode for splitting and unpivoting a Series | |
| # https://stackoverflow.com/questions/19482970/get-list-from-pandas-dataframe-column-headers | |
| def unpivot_delimited_series( | |
| target_series: pd.Series, | |
| delimiter: str | |
| ) -> pd.DataFrame: |
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
| from functools import reduce | |
| # Refactor of this function -> https://gist.github.com/Ze1598/cd32d9867dac11a029937539bac91721#file-get_spotify_playlist_data-py-L58-L73 | |
| def get_artist_counts(artists_info: List[List[Dict]]) -> Dict[str, int]: | |
| """ | |
| Find the frequency of each artist featured in the playlist and return | |
| a dictionary of the type Artist:Frequency. | |
| """ | |
| def map_fn(track_artists: List[Dict]) -> List[str]: | |
| """ |
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
| [ | |
| { | |
| "external_urls": { | |
| "spotify": "https://open.spotify.com/artist/6kNKUYGn6VNGsRoXmyoDPK" | |
| }, | |
| "href": "https://api.spotify.com/v1/artists/6kNKUYGn6VNGsRoXmyoDPK", | |
| "id": "6kNKUYGn6VNGsRoXmyoDPK", | |
| "name": "The Amity Affliction", | |
| "type": "artist", | |
| "uri": "spotify:artist:6kNKUYGn6VNGsRoXmyoDPK" |
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
| { | |
| "album": { | |
| "album_type": "album", | |
| "(...)" | |
| }, | |
| "artists": [ | |
| { | |
| "external_urls": { | |
| "spotify": "https://open.spotify.com/artist/6kNKUYGn6VNGsRoXmyoDPK" | |
| }, |
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
| import pandas as pd | |
| import plotly.express as px | |
| import plotly.graph_objects as go | |
| # Load the data and sort it by artist frequency in descending order | |
| def pre_process_data(file_name: str) -> pd.DataFrame: | |
| dataset = pd.read_csv(file_name) | |
| # Sort the dataset by "Frequency", in descending order, and reset the indices | |
| dataset = dataset.sort_values( |
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
| from os import environ | |
| import spotipy | |
| from spotipy.oauth2 import SpotifyClientCredentials | |
| import pandas as pd | |
| from typing import List, Dict | |
| # https://github.com/plamere/spotipy/blob/master/examples/playlist_tracks.py | |
| # Authenticate to Spotify | |
| def authenticate(cliend_id: str, client_secret: str) -> spotipy.client.Spotify: |