<jupyter_start><jupyter_text><jupyter_code>pip install nflfastpy
import nflfastpy as nfl

df = nfl.load_pbp_data(year=2021)
df.head()
df_weekly = df.groupby(['rusher_id','rusher','week'])['yards_gained'].sum().reset_index()

df_weekly[df_weekly['rusher']=='J.Taylor']
df_weekly = df_weekly[df_weekly['week']<19]
df_weekly = df_weekly.pivot_table(values = 'yards_gained',index = ['week'], columns = 'rusher')

df_weekly.head()
df_weekly.fillna(0, inplace=True)

df_weekly.iloc[:, 0:-1] = df_weekly.iloc[:, 0:-1].cumsum()

df_weekly.head()
top_rushers = set()

for index, row in df_weekly.iterrows():
    top_rushers |= set(row[row > 0].sort_values(ascending=False).head(10).index)

df_weekly = df_weekly[top_rushers]

df_weekly.head()
%%capture
!pip install bar-chart-race
import bar_chart_race as bcr

df_weekly.index = 'Week ' + df_weekly.index.astype(str)

bcr.bar_chart_race(df = df_weekly, 
                   n_bars = 10, 
                   sort='desc',
                   title='2021 Rushing Leaders by Week',
                   period_length=1000,
                   interpolate_period=False,
                   steps_per_period=10,
                   fixed_max=True,
                   filename = '2021_rushing_bar_chart.mp4')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1399209486166008, 'fraction_numerical': 0.02450592885375494, 'mean_word_length': 3.4893617021276597, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '278713', 'license': 'Unlicense', 'n_tokens_mistral': 513, 'n_tokens_neox': 473, 'n_words': 69, 'path': 'NFLRush_BCR.ipynb', 'repo_name': 'eforta-stack/DS-Projects', 'size': '1265'}