<jupyter_start><jupyter_text>IS-445-FINAL-Presentation  Group L+ <NAME>+ <NAME>+ <NAME>+ <NAME><jupyter_code>import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import ipywidgets
import warnings
import seaborn as sns
import plotly.graph_objects as go
import plotly.express as px
warnings.filterwarnings("ignore")
# Load data 
tennis_df = pd.read_csv("https://raw.githubusercontent.com/ericL1u/IS-445-FInal-GroupProject/main/ATP.csv",  
                        dtype=str)
df = tennis_df<jupyter_output><empty_output><jupyter_text>TENNIS DATASET<jupyter_code>tennis_df
# Create new columns storing year and year/month attributes
df['tourney_yearmonth'] = df.tourney_date.astype(str).str[:6]
df['tourney_year'] = df.tourney_date.astype(str).str[:4]
df['tourney_year'] = df['tourney_year'].astype(int)
winners = df['winner_name'].value_counts()
losers = df['loser_name'].value_counts()

winners_df = pd.DataFrame(df['winner_name'].value_counts())
winners_df['name'] = winners_df.index
winners_df['win_count'] = winners_df['winner_name']
winners_df.drop(['winner_name'], axis = 1, inplace = True)
winners_df.reset_index(inplace = True, drop = True)
losers_list = winners_df['name'].to_list()
#losers_list
losers = losers.reindex(losers_list, axis = 0)
winners_df['lost_count'] = losers.values
winners_df['total'] = winners_df['win_count'] + winners_df['lost_count']
new_df = winners_df.iloc[0:10]<jupyter_output><empty_output><jupyter_text>DAKSH SHAH<jupyter_code>f, ax = plt.subplots(figsize=(15, 10))
sns.set_color_codes("pastel")
sns.barplot(x="total", y="name", data=new_df, label="Total Played", color="b")
sns.set_color_codes("muted")
sns.barplot(x="win_count", y="name", data=new_df, label="Wins", color="b")
ax.legend(ncol=1, loc="lower right", frameon=True)
ax.set(xlim=(0, 1800), ylabel="Top 10 players",
       xlabel="Matches", title="Players' win ratios with most matches")
sns.despine(left=True, bottom=False)
@ipywidgets.interact(surface = ['Hard', 'Grass', 'Clay', 'Carpet'])

def position(surface):
    ret_df = df[df['score'].str.contains("RET")==True][['tourney_year','tourney_level','surface','tourney_id','winner_name']]
    ref_df_f = ret_df.groupby(['tourney_year','surface'], as_index=False).agg('count')
    
    fig = plt.figure(figsize=(15,5))
    ax = fig.add_subplot(111)
    plt.style.use('seaborn-colorblind')
    
    plt.title('Retirements - Evolution of Retirements by Surface')
    plt.ylabel('Number of Retirements')
    plt.xlabel('Year')
    
    plt.plot(ref_df_f[ref_df_f['surface']==surface]['tourney_year'], ref_df_f[ref_df_f['surface']==surface]['tourney_id'], linestyle='solid', linewidth=2)
fserves = df['w_1stIn'].value_counts()
fserves_list = winners_df['name'].to_list()
fserves = fserves.reindex(fserves_list, axis = 0)
winner_hands= pd.DataFrame(df.winner_hand.value_counts())
loser_hands= pd.DataFrame(df.loser_hand.value_counts())
x= winner_hands + loser_hands
df_xyz= winner_hands.copy()
df_xyz['new'] = loser_hands['loser_hand']
hands= pd.concat([winner_hands,loser_hands], axis = 1)
hands['total_matches_played']= hands['winner_hand']+ hands['loser_hand']
temp  = df[['winner_name', 'winner_hand']].drop_duplicates('winner_name')<jupyter_output><empty_output><jupyter_text><NAME><jupyter_code>x = np.arange(len(hands.index)) 
width = 0.30 

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, (hands['winner_hand']/hands['total_matches_played'])*100, width, label='Winner Hand')
rects2 = ax.bar(x + width/2, (hands['loser_hand']/hands['total_matches_played'])*100, width, label='Loser Hand')

ax.set_ylabel('Total Matches')
ax.set_title('Wins VS Loss for Right, Left and Ambidextrous players')
ax.set_xticks(x)
ax.set_xticklabels(hands.index)
ax.legend()

#ax.bar_label(rects1, padding=3)
#ax.bar_label(rects2, padding=3)

fig.tight_layout()

plt.show()
temp  = df[['winner_name', 'winner_hand']].drop_duplicates('winner_name')
no_winners_hand = df['winner_hand'].value_counts()
no_losers_hand = df['loser_hand'].value_counts() 
df["winner_name_bool"] = df.winner_name.isin(['<NAME>','<NAME>','<NAME>'])
fav_players_winner = df[(df["winner_name_bool"]==True)]

df["loser_name_bool"] = df.loser_name.isin(['<NAME>','<NAME>', '<NAME>'])
fav_players_loser = df[(df["loser_name_bool"]==True)]
winner_xyz= fav_players_winner[["winner_name","w_1stIn","tourney_year"]]['winner_name'].groupby(fav_players_winner['tourney_year']).value_counts()
winner_xyz = winner_xyz[~winner_xyz.index.get_level_values(0).isin([1998, 1999])]
df_winner = pd.DataFrame()
df_winner['Winner_Tourney_Year'] = winner_xyz.index.get_level_values(0)
df_winner['Winner_Player_Name'] = winner_xyz.index.get_level_values(1)
df_winner['Win_Serve_Count'] = winner_xyz.values
df_winner = df_winner[~df_winner['Winner_Tourney_Year'].isin([1998,1999])]
df_winner.reset_index(inplace = True, drop = True)
loser_xyz= fav_players_loser[["loser_name","l_1stIn","tourney_year"]]['loser_name'].groupby(fav_players_loser['tourney_year']).value_counts()
df_loser = pd.DataFrame()
df_loser['Loser_Tourney_Year'] = loser_xyz.index.get_level_values(0)
df_loser['Loser_Player_Name'] = loser_xyz.index.get_level_values(1)
df_loser['Loss_Serve_Count'] = loser_xyz.values
df_loser = df_loser[~df_loser['Loser_Tourney_Year'].isin([1998,1999])]
df_loser.reset_index(inplace = True, drop = True)
merged_df = pd.concat([df_winner, df_loser],axis=1)
new_df = pd.merge(df_winner, df_loser,  how='left', left_on=['Winner_Tourney_Year','Winner_Player_Name'], right_on = ['Loser_Tourney_Year','Loser_Player_Name'])
new_df['Win_Percentage']= (new_df['Win_Serve_Count']/(new_df['Loss_Serve_Count']+new_df['Win_Serve_Count']))*100
new_df['Loss_Percentage']= 100.00- new_df['Win_Percentage']
fig = go.Figure()

fig = px.line(new_df, x=list(new_df['Winner_Tourney_Year']), y=list(new_df['Win_Percentage']),color = 'Winner_Player_Name',
              labels={
                     "Winner_Player_Name": "PLAYER NAME"
                 })

fig.update_layout(
    title_text="PERFORMANCE COMPARISON OF 3 PLAYERS ON THE BASIS OF SERVES WON",
    xaxis_title="YEAR",
    yaxis_title="PERCENTAGE OF SERVES WON",
)
 

fig.update_layout(
    xaxis=dict(
        rangeslider=dict(
            visible=True
        ),
        type="date"
    )
)

fig.show()
# Convert numerical values to float
numeric_columns = ['w_ace', 'l_ace', 'w_df', 'l_df', 'w_bpSaved', 'l_bpSaved', 'winner_rank', 'loser_rank', 'winner_age', 'loser_age', 'winner_ht', 'loser_ht', 'w_svpt', 'l_svpt', 'minutes']
tennis_df[numeric_columns] = tennis_df[numeric_columns].astype(float)
# Create new columns storing year and year/month attributes
tennis_df['tourney_yearmonth'] = tennis_df.tourney_date.astype(str).str[:6]
tennis_df['tourney_year'] = tennis_df.tourney_date.astype(str).str[:4]
tennis_df['tourney_year'] = tennis_df['tourney_year'].astype(int)<jupyter_output><empty_output><jupyter_text>DEZHOU CHEN<jupyter_code>@ipywidgets.interact(country = ['ARG','ESP','SUI','USA','SRB'])

def position(country):
    s = tennis_df[(tennis_df['tourney_level'] == 'G') & (tennis_df['winner_ioc'].isin([country]))].groupby(['tourney_year','winner_ioc']).agg('count')
    plt.plot(s['tourney_id'].index.get_level_values(0), s['tourney_id'].values, color='blue', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=2, label='Argentina')<jupyter_output><empty_output><jupyter_text>GUANGYUAN LIU<jupyter_code>@ipywidgets.interact(dimensions = ['winner_rank','loser_rank','winner_age','loser_age','winner_ht','loser_ht','w_svpt','l_svpt'])


def position(dimensions):
    tennis_df[dimensions].plot(kind='hist',title = dimensions,figsize=(15,5), stacked=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17252187540812328, 'fraction_numerical': 0.01319054459971268, 'mean_word_length': 7.915017462165308, 'pattern_counts': {'":': 1, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 1, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '173739', 'license': 'MIT', 'n_tokens_mistral': 3142, 'n_tokens_neox': 2975, 'n_words': 385, 'path': 'app445.ipynb', 'repo_name': 'ericL1u/IS-445-FInal-GroupProject', 'size': '7729'}