setting period value as index +1 in bar chart race, python

44 views Asked by At

Running bar chart race works for me with the code,

import bar_chart_race as bcr
bcr.bar_chart_race(df = df_tp, 
                   n_bars = 10, 
                   sort='desc',
                   period_fmt='Gameweek {x:.0f}',
                   period_length=1500,
                   steps_per_period = 20,
                   title='my title',
                   filename = 'fpl.mp4',
                   interpolate_period = 'false'
                   )

but when I try to add {x:.0f + 1} it gives me the error:

Exception: You do not have ffmpeg installed on your machine. Download
                            ffmpeg from here: https://www.ffmpeg.org/download.html.
                            
                            Matplotlib's original error message below:

                            Invalid format specifier

I have installed ffmpeg so not sure why it happens. My problem is that I want to print out gameweeks and it prints out the index number instead, so it starts from 0 and ends 1 early. Is there a way to add +1 or for it to retrieve the value from my 'gameweek' column instead (which contains the correct numbers)?

1

There are 1 answers

0
Jahlove On

A work around was changing the index of the dataframe

df = df.set_index('gameweek')
df.index.name = 'gameweek'