{"id":24074705,"url":"https://github.com/joicodes/top-100-racing-bar-chart","last_synced_at":"2025-06-21T18:05:02.539Z","repository":{"id":233089940,"uuid":"298828282","full_name":"joicodes/Top-100-Racing-Bar-Chart","owner":"joicodes","description":"Racing bar chart animation of artists with the most Billboard Hot 100 Entries  using the pandas and data visualization libraries in Python 3.","archived":false,"fork":false,"pushed_at":"2020-09-28T03:19:00.000Z","size":6033,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T18:59:33.673Z","etag":null,"topics":["bar-chart-race","billboard-charts","billboard100","billboards-hot-100","data-visualization","pandas","pandas-python","pandas-tutorial","python-3","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joicodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-09-26T14:12:54.000Z","updated_at":"2024-12-20T20:28:37.000Z","dependencies_parsed_at":"2024-04-13T18:42:12.539Z","dependency_job_id":"3dd440ae-a26c-48c8-9edc-6396503fedad","html_url":"https://github.com/joicodes/Top-100-Racing-Bar-Chart","commit_stats":null,"previous_names":["joicodes/top-100-racing-bar-chart"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/joicodes/Top-100-Racing-Bar-Chart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joicodes%2FTop-100-Racing-Bar-Chart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joicodes%2FTop-100-Racing-Bar-Chart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joicodes%2FTop-100-Racing-Bar-Chart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joicodes%2FTop-100-Racing-Bar-Chart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joicodes","download_url":"https://codeload.github.com/joicodes/Top-100-Racing-Bar-Chart/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joicodes%2FTop-100-Racing-Bar-Chart/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261170422,"owners_count":23119512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bar-chart-race","billboard-charts","billboard100","billboards-hot-100","data-visualization","pandas","pandas-python","pandas-tutorial","python-3","python3"],"created_at":"2025-01-09T18:19:52.730Z","updated_at":"2025-06-21T18:04:57.477Z","avatar_url":"https://github.com/joicodes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Create a Race Bar in Python\nTutorial Prepared by: Joi Anderson ([@joicodes](https://github.com/joicodes)) • [View on Notion](https://www.notion.so/Create-a-Race-Bar-in-Python-6ad8b31aeb2849ebb5fcb27e0bdb1831) • Updated: Sept. 27, 2020\n\n\u003cbr/\u003e\n\n### **Step 1: Curate a Data File 📊**\n\u003cbr/\u003e\n\n**Finding an interesting data set:**\n\nA **data set** is a collection of data. \n\nData sets are created in many different ways. Some are based off of human observations or surveys, like the U.S. Census. Others may be machine-generated, like satellite forecast data.\n\nThe most common format for data sets is a spreadsheet or CSV. Let's aim to find a dataset that is formatted as a CSV. \n\nHere is a list of sources for interesting data sets to explore:\n\n- [data.world](https://www.data.world/)\n- [FiveThirtyEight](http://fivethirtyeight.com/)\n- [Google Public Data Sets](https://cloud.google.com/bigquery/public-data/)\n- [/r/datasets](https://www.reddit.com/r/datasets/top/?sort=top\u0026t=all) (on Reddit)\n- [DataSF](https://datasf.org/opendata/)\n\n👉🏽 For this workshop, we will be using:  [Hot 100 singles (1/1/2000 and 12/28/2019)](https://docs.google.com/spreadsheets/d/1Wcu85wPRwyZN4I41gBFCbweCjxcvNs7xPlZ9rkddzQQ/edit?usp=sharing/copy)\n\n\u003cbr/\u003e\n\n**Understanding Your Data:**\n\nBefore starting your analysis on the data set, let's take the time to first understand the data we are working with. So let's take a look at the data: \n\n\u003cbr/\u003e\n\n![readme_assets/Untitled.png](readme_assets/Untitled.png)\n\n\n\nObservations:\n\n- **About**: New Hot 100 singles from January 1, 2000 to December 28, 2019\n- **Data Source**: Web scrapped from [Billboard.com](https://www.billboard.com/charts/hot-100)\n- **Size**: 7,850 rows of data (i.e. 7,850 songs)\n- The first row of my data contains column names.\n- **Columns**:\n    - `Week` -  The week the song entered the Billboard Hot 100\n    - `EnterPosition` - The position the song entered the Billboard Hot 100\n    - `Song` - Name of the song\n    - `Performer` - Name of the performer and features on the song.\n\n\u003cbr/\u003e\n\n**Download Data** \n\nExport the Google Sheets file as a CSV and move it to our repository:\n\n```bash\nFile \u003e Download \u003e Comma Separated Values (.csv, current sheet)\n```\n\nRename the file `hot100.csv` and add it to your repository. \n\n\n**👀 Here is how your data looks as a raw CSV file: [Preview](https://raw.githubusercontent.com/joicodes/Top-100-Racing-Bar-Chart/master/hot100.csv)**\n\n\n\u003cbr/\u003e\n\n---\n\n\u003cbr/\u003e\n\n### **Step 2: Using Pandas 🐼**\n\n\u003cbr/\u003e\n\n**Meet Pandas (Python Data Analysis Library)**\n\n`pandas` is a Python library that give you a set of tool to do data analysis. \nIf want to work with big data sets, then `pandas` is going to be your best friend. 👯‍♀️\n\n![readme_assets/Startimage.gif](readme_assets/Startimage.gif)\n\n*Image from: [Python Awesome](https://pythonawesome.com/bokeh-plotting-backend-for-pandas-and-geopandas/)*\n\n\u003cbr/\u003e\n\nTo install `pandas`, in your Terminal write:\n\n```bash\npip3 install pandas\n```\n\n\u003cbr/\u003e\n\nAfter it installs, we can import it into our `[main.py](http://main.py)` file:\n\n```python\nimport pandas as pd\n```\n\n\u003cbr/\u003e\n\n**Loading our data from CSV file** \n\n\u003cbr/\u003e\n\nNow that we've imported `pandas`, we are ready to read the CSV file into Python using `read_csv()` from `pandas`:\n\n```python\ndata_frame = pd.read_csv(\"hot100.csv\")\n```\n\n\u003cbr/\u003e\n\nTo see if it worked, we can see the first few rows of the data by adding the following to our code:\n\n```python\nprint( data_frame.head() ) \n```\n\n\u003cbr/\u003e\n\n`head()` gives us a snap shot of our data, by displaying  the first few rows and columns of the data set. \n\nYou should an aggregated chart printed to the terminal like this: \n\n\u003cbr/\u003e\n\n![readme_assets/Untitled%201.png](readme_assets/Untitled%201.png)\n\n\n\nWe can also see the last rows of the data by using `tail()`\n\n```python\nprint( data_frame.tail() )\n```\n\n\u003cbr/\u003e\n \n\n![readme_assets/Untitled%202.png](readme_assets/Untitled%202.png)\n\n\n---\n\n\n### **Step 3: Install Bar Chart Race 🏁**\n\n\u003cbr/\u003e\n\n**Meet Bar Chart Race** \n\n\u003cbr/\u003e\n\n`bar_chart_race` is an open source Python library that can be used to create animated bar and line chart races in Python. It's is built on top of two popular Python data analytics library: `matplotlib` and `plotly`. This library simplifies creating racing graph animation!\n\n\u003cbr/\u003e\n\n👉🏽  See [repo](https://github.com/dexplo/bar_chart_race)\n\n\u003cbr/\u003e\n\n![readme_assets/covid19_horiz.gif](readme_assets/covid19_horiz.gif)\n\nTo install `bar_chart_race`, in your Terminal write:\n\n```bash\npip3 install bar_chart_race\n```\n\n\u003cbr/\u003e\n\nAfter it installs, we can import it into our `[main.py](http://main.py)` file:\n\n```python\nimport bar_chart_race as bcr\n```\n\n\u003cbr/\u003e\n\n**Install Dependency**\n\n```python\nbrew install ffmpeg\n```\n\n\u003cbr/\u003e\n\nIf you decide that you want to create a gif animation, install **Image Magick** and **Ghost Script**\n\n```jsx\nbrew install imagemagick\nbrew install ghostscript\n```\n\n\n\n---\n\n\u003cbr/\u003e\n\n### **Step 4: Prepare Data for Bar Chart 🔧**\n\n\u003cbr/\u003e\n\n**Transform data into 'wide' data** \n\n\u003cbr/\u003e\n\nIn order to create a racing bar chart, our data set must be in '**wide**' form where:\n\n- Each row represents a single period of time\n- Each column holds the value for a particular category\n- The index contains the time component\n\n\n\u003cbr/\u003e\n\n\nTo transform our data set into **wide** form we would need:\n\n- The index would be the week — using `Week`\n- Each column has a name an artists who had a Top 100 hit — using `Performer`\n- Each row should represent the cumulative count of songs by that week.\n\n\n\u003cbr/\u003e\n\n\nHere a rough sketch of how it would look :\n\n\u003cbr/\u003e\n\n![readme_assets/Untitled%203.png](readme_assets/Untitled%203.png)\n\nWe can transform  to be '**wide'** by creating a pivot table with `pandas`:\n\n```python\nwide_data = data_frame.pivot_table(index='Week', columns='Performer', aggfunc='count', fill_value=0).cumsum()\n```\n\n\u003cbr/\u003e\n\n\n\n\nHere is what `wide_data.head()` will print:\n\u003cbr/\u003e\n\n![readme_assets/Untitled%204.png](readme_assets/Untitled%204.png)\n\n**If you want to see the full output, check it out [here](https://raw.githubusercontent.com/joicodes/Top-100-Racing-Bar-Chart/master/wide_data.csv).**\n\n\u003cbr/\u003e\n\n**Remove header**\n\n\u003cbr/\u003e\n\nThe pivot table generated a header for us that is not useful to us.\n\nWe can remove this header by using `drop level()` :\n\n```python\nwide_data.columns = wide_data.columns.droplevel(0)\n```\n\n\u003cbr/\u003e\n\n**Remove duplicate columns**\n\nIf you look at the results, there are some duplicated columns:\n\n```python\nwide_data = wide_data.loc[:,~wide_data.columns.duplicated()] \n```\n\n\u003cbr/\u003e\n\n**Create a subset**\n\nThere are hundreds of artists with Billboard Hot 100 hits. Our graph would be wayyyy too big if we decided to make all artists race. Let's shorten our table to 5 columns to compare.\n\nRather than deleting the columns we are currently not using, we can create a subset with the columns we need with `pandas`:\n\nLet's choose **5 Performers** (i.e. 5 columns of data) to race and store them in a list:\n\n\u003cbr/\u003e\n\n```python\ncolumns = [ \"Mariah Carey\", \"Michael Jackson\", \"Drake\", \"Rihanna\", \"Lady Gaga\"]\n```\n\n\u003cbr/\u003e\n\nUsing that list of column names, we can create a sub-dataset by doing the following:\n\n```python\nsub_dataset = data_frame[columns]\n```\n\n\u003cbr/\u003e\n\nLet's print the first few rows of `sub_dataset` to what data it contains:\n\n```python\nprint(sub_dataset.head())\n```\n\n\u003cbr/\u003e\n\n\n\nNow that we have our data ready... let the games begin!\n\n---\n\n### **Step 5: Create Your Animation 🏁**\n\n\u003cbr/\u003e\n\n**Create .mp4 with Racing Bar Chart Animation**\n\n```jsx\nbcr.bar_chart_race(sub_dataset, filename='hot100.mp4')\n```\n\n\u003cbr/\u003e\n\n**Check out your video** \n\nOnce your program has finished, check your repo for `hot100.mp4` and watch your 5 artists race!\n\nWhich artists did you choose? Were you surprised about who won?\n\nHere is mine (watch in 5x speed):\n\n[https://youtu.be/mgFmybMTnXs](https://youtu.be/mgFmybMTnXs)\n\n\n\n\n**Check the [docs](https://www.dexplo.org/bar_chart_race/) for Bar Chart Race to customize your animation!**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoicodes%2Ftop-100-racing-bar-chart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoicodes%2Ftop-100-racing-bar-chart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoicodes%2Ftop-100-racing-bar-chart/lists"}