text_html_output_1.png
import numpy as np

import pandas as pd

df = pd.read_csv('/kaggle/input/playoff_shots.csv')

def shooting_summary(df, by):
    df_summary = df.copy()
    df_3p = df_summary[df_summary['shot_type'] == '3PT']
    df_2p = df_summary[df_summary['shot_type'] == '2PT']
    df_ft = df_summary[df_summary['shot_type'] == 'FT']
    result = pd.DataFrame()
    all_make = df_summary[df_summary['result'] == 'make'].groupby(by).count()['game_id']
    all_miss = df_summary[df_summary['result'] == 'miss'].groupby(by).count()['game_id']
    result['Shot Attempts'] = all_make + all_miss
    result['Shot %'] = all_make / result['Shot Attempts'] * 100
    make_3p = df_3p[df_3p['result'] == 'make'].groupby(by).count()['game_id']
    miss_3p = df_3p[df_3p['result'] == 'miss'].groupby(by).count()['game_id']
    result['3p Attempts'] = make_3p + miss_3p
    result['3p %'] = make_3p / result['3p Attempts'] * 100
    make_2p = df_2p[df_2p['result'] == 'make'].groupby(by).count()['game_id']
    miss_2p = df_2p[df_2p['result'] == 'miss'].groupby(by).count()['game_id']
    result['2p Attempts'] = make_2p + miss_2p
    result['2p %'] = make_2p / result['2p Attempts'] * 100
    make_ft = df_ft[df_ft['result'] == 'make'].groupby(by).count()['game_id']
    miss_ft = df_ft[df_ft['result'] == 'miss'].groupby(by).count()['game_id']
    result['FT Attempts'] = make_ft + miss_ft
    result['FT %'] = make_ft / result['FT Attempts'] * 100
    result['TS Proportion'] = result['Shot Attempts'] / np.sum(result['Shot Attempts']) * 100
    return result

list(df['game_description'].unique())[78:]