{"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.12.2"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":30573,"databundleVersionId":2683891,"sourceType":"competition"}],"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as npimport pandas as pdimport matplotlib as mplimport matplotlib.pyplot as pltimport seaborn as snsplt.style.use('fivethirtyeight')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games = pd.read_csv('games.csv')games","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def downcast(df, verbose=True):    start_mem = df.memory_usage().sum() / 1024**2    for col in df.columns:        dtype_name = df[col].dtype.name        if dtype_name == 'object':            pass        elif dtype_name == 'bool':            df[col] = df[col].astype('int8')        elif dtype_name.startswith('int') or (df[col].round() == df[col]).all():            df[col] = pd.to_numeric(df[col], downcast='integer')        else:            df[col] = pd.to_numeric(df[col], downcast='float')    end_mem = df.memory_usage().sum() / 1024**2    if verbose:        print('{:.1f}% Compressed'.format(100 * (start_mem - end_mem) / start_mem))        return df","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games = downcast(games)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def resumetable(df):    print(f'Shape : {df.shape}')    summary = pd.DataFrame(df.dtypes, columns=['Data Type'])    summary = summary.reset_index()    summary = summary.rename(columns={'index': 'Feature'})    summary['Num of null'] = df.isnull().sum().values    summary['Num of unique'] = df.nunique().values    summary['First value'] = df.loc[0].values    summary['Second value'] = df.loc[1].values    summary['Third value'] = df.loc[2].values    return summaryresumetable(games)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def write_percent(ax, total_size):    '''Traverse the figure object and display the ratio at the top of the bar graph.'''    for patch in ax.patches:        height = patch.get_height() # Figure height (number of data)        width = patch.get_width() # Figure width        left_coord = patch.get_x() # The x-axis position on the left edge of the figure        percent = height/total_size*100 # percent                # Type text in the (x, y) coordinates        ax.text(x=left_coord + width/2.0, # x-axis position                y=height + total_size*0.001, # y-axis position                s=f'{percent:1.1f}%', # Text                ha='center') # in the middle","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"games['month'] = games['gameDate'].apply(lambda x: int(x.split('/')[0]))games['day'] = games['gameDate'].apply(lambda x: int(x.split('/')[1]))games['hour'] = games['gameTimeEastern'].apply(lambda x: int(x.split(':')[0]))","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mpl.rc('font', size=15) # Set font sizeplt.figure(figsize=(7, 6)) # Set figure sizeax = sns.countplot(x='season', data=games)write_percent(ax, len(games)) ax.set_title('Number of games for season');","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mpl.rc('font', size=15)plt.figure(figsize=(8, 6))ax = sns.countplot(x='month', data=games)write_percent(ax, len(games))ax.set_title('Number of games for month');","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mpl.rc('font', size=12) plt.figure(figsize=(15, 7))ax = sns.countplot(x='day', data=games)write_percent(ax, len(games))ax.set_title('Number of games for day');","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mpl.rc('font', size=12) plt.figure(figsize=(15, 7))ax = sns.countplot(x='gameTimeEastern', data=games)write_percent(ax, len(games))ax.set_title('Number of games for gameTimeEastern');ax.tick_params('x', labelrotation=30) # rotate 30 degree of x label","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mpl.rc('font', size=12) plt.figure(figsize=(15, 7))ax = sns.countplot(x='hour', data=games)write_percent(ax, len(games))ax.set_title('Number of games for hour');","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mpl.rc('font', size=12) plt.figure(figsize=(15, 7))ax = sns.countplot(x='week', data=games)write_percent(ax, len(games))ax.set_title('Number of games for week');","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}