<jupyter_start><jupyter_text>1. Plot By Avg Number of Shifts/Player<jupyter_code>## Load Dataframes
game_df = pd.read_csv('data/upd_game.csv')
team_to_analyze = '<NAME>'
game_df = game_df[(game_df.home_team_name == team_to_analyze) |\
                 (game_df.away_team_name == team_to_analyze)]

## Get Stats For Winning Teams
winning_df = game_df.apply(lambda x: get_winning_stats(x),axis = 1)

## Create Win Count 
win_cnt = winning_df.groupby('winner_avgNumShift')\
.agg({'winner':'count'}).reset_index()
win_cnt.columns = ['avgNumShift','win_count']

## Create Loss Count
los_cnt = winning_df.groupby('loser_avgNumShift')\
.agg({'loser':'count'}).reset_index()
los_cnt.columns = ['avgNumShift','loss_count']

## Merge Counts
winlos_cnt = win_cnt.merge(los_cnt)
winlos_cnt['win_ratio'] = winlos_cnt['win_count'] /\
(winlos_cnt['win_count'] + winlos_cnt['loss_count'])

# ## Remove Outliers
winlos_cnt = winlos_cnt[winlos_cnt.avgNumShift >= 18]
winlos_cnt = winlos_cnt[winlos_cnt.avgNumShift <= 24]

%matplotlib inline
winlos_cnt[['avgNumShift','win_ratio']].plot(x='avgNumShift',kind = 'bar')<jupyter_output><empty_output><jupyter_text>2. Plot by Avg Ice Time<jupyter_code>## Get Stats For Winning Teams
winning_df = game_df.apply(lambda x: get_winning_stats(x),axis = 1)

## Create Win Count 
win_cnt = winning_df.groupby('winner_avgIceTime')\
.agg({'winner':'count'}).reset_index()
win_cnt.columns = ['avg_IceTime','win_count']

## Create Loss Count
los_cnt = winning_df.groupby('loser_avgIceTime')\
.agg({'loser':'count'}).reset_index()
los_cnt.columns = ['avg_IceTime','loss_count']

## Merge Counts
winlos_cnt = win_cnt.merge(los_cnt)

## Remove Outliers
winlos_cnt = winlos_cnt[winlos_cnt.avg_IceTime >= 500]
winlos_cnt = winlos_cnt[winlos_cnt.avg_IceTime <= 1060]

## Bin Data, Group, and Calc Winrate
winlos_cnt['bins'] = pd.cut(winlos_cnt.avg_IceTime,bins=range(950,1070,10))
winlos_cnt = winlos_cnt.groupby('bins').agg({'win_count':'sum','loss_count':'sum'})
winlos_cnt['win_ratio'] = winlos_cnt['win_count'] /\
(winlos_cnt['win_count'] + winlos_cnt['loss_count'])
winlos_cnt.reset_index(inplace= True)

#Plot
%matplotlib inline
winlos_cnt[['bins','win_ratio']].plot(x = 'bins',kind = 'bar')<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup