Example #1
0
def get_slg_pfx(df):
    """
    Calculate slugging from a pitchab dataframe
    SLG = (Total bases) / (At Bats)
    """
    tb = Baseball.get_tb(df)
    ab = Baseball.get_atbats_count_pfx(df)
    return(tb/ab) 
Example #2
0
def hits_tb_per_pitch(df):
    """
    From a pitchab dataframe return a dict containing
        Pitches
        Hits
        Total Bases
        Total Bases per pitch'
    """
    tb = Baseball.get_tb(df)
    hits = get_hits(df)
    if len(df) == 0:
        tb_per_pitch = 0
    else:
        tb_per_pitch = tb/len(df)
    return {'Pitches':len(df),
            'Hits':len(hits),
            'TB':tb,
            'TB_per_pitch':tb_per_pitch}
Example #3
0
def get_slg_per_atbat_pfx(df): 
    """Calculate Total bases per ATBAT """ 
    ab = len(Baseball.get_atbats_df_pfx(df))
    tb = Baseball.get_tb(df)
    return tb/len(events)