How to Create a Bar Chart Race From Excel Data With Python
A bar chart race turns a time series into an animated ranking. Put one row per date and one column per item in Excel, read the sheet with pandas, and one call to the bar-chart-race library renders the frames and saves them as an MP4 video through ffmpeg. The library is no longer maintained, so it needs pandas below 3.0.

Lay out the data
bar-chart-race expects a wide table: one row per period with the date in the first column, and one column per item that races. My Salesdata.xlsx has a Date column and one column per store, Store A to Store F, with the cumulative sales for each day.

If your data is a long list instead, with one row per date and store, pivot it first with df.pivot(index="Date", columns="Country", values="Sales"), using your own column names.
Install the packages and ffmpeg
The library’s last release, 0.1.0, came out in June 2020. It still runs with pandas 2.x, but pandas 3.0 removed fillna(method=...), which the library calls internally, so it fails there with a TypeError. Install it together with an older pandas:
pip install bar_chart_race "pandas<3" openpyxl
For the MP4 export you also need ffmpeg on your PATH. Check it with ffmpeg -version in a terminal. If you would rather use a maintained library that needs no ffmpeg, my animated bar chart with Plotly builds a similar race from Excel data.
The script
The core is one call, bcr.bar_chart_race(df=df, filename=...), on a DataFrame with the dates as index. Every other argument styles the chart. This version shows the six largest stores in descending order, with the date and the total sales of those six in the bottom right corner.
import pandas as pd
import bar_chart_race as bcr
df = pd.read_excel('Salesdata.xlsx')
df.set_index('Date', inplace=True)
# Documentation: https://pypi.org/project/bar-chart-race/
bcr.bar_chart_race(
df=df,
filename='Salesdata.mp4',
orientation='h',
sort='desc',
n_bars=6,
fixed_order=False,
fixed_max=True,
steps_per_period=10,
interpolate_period=False,
label_bars=True,
bar_size=.95,
period_label={'x': .99, 'y': .25, 'ha': 'right', 'va': 'center'},
period_fmt='%B %d, %Y',
period_summary_func=lambda v, r: {'x': .99, 'y': .18,
's': f'Total Sales: {v.nlargest(6).sum():,.0f}',
'ha': 'right', 'size': 8, 'family': 'Courier New'},
period_length=500,
figsize=(12, 6),
dpi=300,
cmap='dark12',
)
To start the script from Excel with a button instead of the command line, see running a Python script from Excel with VBA.
Export as MP4 or GIF
The export happens inside the same call. Because the filename ends in .mp4, bar_chart_race hands the frames to ffmpeg. For an animated GIF, use a .gif filename; the library’s documentation says that needs ImageMagick. Leave out the filename and, in a Jupyter notebook, the animation plays inline instead.

With dpi=300 and many periods, rendering takes a while. Lower the dpi or steps_per_period for a quick test run.
