This chart was generated in Google Colaboratory. Raw Data from IMF open source.
Install Package:
! pip install bar_chart_race
Import Libraries:
import pandas as pd
import numpy as np
import bar_chart_race as bcr
Read Dataset:
df = pd.read_excel("gdp.xlsx")
df
Shape Dataset (Rows to Columns, Columns to Rows):
df.set_index("Country", inplace=True)
df = df.T
print(f"Dataframe has {df.shape[0]} rows and {df.shape[1]} columns")
df.head()
Change data type 'object' to 'numeric':
df = df.apply(lambda x: pd.to_numeric(x, errors='coerce') if x.dtype == "object" else x)
Animated Bar Chart Generation (10 bars):
bcr.bar_chart_race(df, n_bars = 10)
There are still plenty of adjustments can be made for the visualization. It's just an example of how easy to create animated chart.
Comments