Hello Everyone! My name is Andrew Fung, in this video, we will be using the Python Pandas and Bar Chart Race library to visualise the COVID-19 Cases by Country from late January 2020 til now.
#python #pandas #racebar #covid-19 #dataVisualization
John Hopkins University dataset: https://github.com/CSSEGISandData/COV...
Installation and Setup!
Installing Bar Chart Race library: https://www.dexplo.org/bar_chart_race...
Installing Jupyter Notebook: https://jupyter.readthedocs.io/en/lat...
Installing the Python Pandas library: https://pandas.pydata.org/pandas-docs...
Bar Chart Race Overall Documentation: https://www.dexplo.org/bar_chart_race/
Check out my Github!
https://github.com/Andrew-FungKinHo
How I make my YouTube videos:
⌨️ Keyboard - Nuphy Air75 Mechanical Keyboard - https://amzn.to/3Xu4PD3
🎙 Microphone - MAONO A04 Professional Podcaster USB Microphone - https://amzn.to/3k8ocD5
🖱 Mouse - Microsoft Bluetooth Ergonomic Mouse - https://amzn.to/3CHhdHJ
🔌 Accessories - Laptop Docking Station for MacBook Pro - https://amzn.to/3CHi5Mv
Timestamps
0:00 | Introduction
2:41 | Data cleaning and manipulation
14:32 | Data selection and pre-processing
21:13 | Plotting and customisation
27:27 | Final Plot Demo
Full code:
———————————————————————————————
import pandas as pd
import bar_chart_race as bcr
open csv file from John Hopkins university
df = pd.read_csv('time_series_covid19_confirmed_global.csv')
remove longitude and latitude values
df = df.drop(columns=["Lat","Long"])
combine Province/State and Country/Region and make a new column called Location
df['Location'] = df[['Province/State','Country/Region']].apply(lambda x: ', '.join(x.dropna()),axis=1)
remove Province/State and Country/Region columns
df = df.drop(columns=['Province/State', 'Country/Region'])
move the combined values to the first column
cols = list(df.columns)
cols = [cols[-1]] + cols[:-1]
df = df[cols]
transpose the dataframe by flipping the columns and rows
df_transposed = df.T
df_transposed.columns = df_transposed.iloc[0].to_list()
df_transposed = df_transposed.iloc[1:]
df_transposed
label the index as "Date"
df_transposed.index.names = ['Date']
specify countries to be included for pre-processing ()
cols = ['Hubei, China','Germany','Spain','United Kingdom','US','India', 'Brazil','Russia','France','Italy']
subset = df_transposed[cols]
create a new dataframe and make sure all the cells are in a numeric form
cum_sum_df = subset.cumsum(axis=0)
cum_sum_df = cum_sum_df.apply(pd.to_numeric)
turn index to datetime objects
cum_sum_df.index = pd.to_datetime(cum_sum_df.index)
plot the racebars
bcr.bar_chart_race(
df=cum_sum_df,
title="COVID-19 Case by country",
filename="covid-19-visualization.mp4",
period_fmt="%b %-d, %Y",
n_bars=8,
steps_per_period=100,
interpolate_period=True
)
———————————————————————————————
Feel free to drop a like and comment if you enjoy and video and let me know if you want me to do other types of programming videos ;) !!!