sportsref/nba/pbp.py
def clean_features(df):
    """Fixes up columns of the passed DataFrame, such as casting T/F columns to
    boolean and filling in NaNs for team and opp.

    :param df: DataFrame of play-by-play data.
    :returns: Dataframe with cleaned columns.
    """
    df = pd.DataFrame(df)

    bool_vals = set([True, False, None, np.nan])
    sparse_cols = sparse_lineup_cols(df)
    for col in df:

        # make indicator columns boolean type (and fill in NaNs)
        if set(df[col].unique()[:5]) <= bool_vals:
            df[col] = (df[col] == True)

        # fill NaN's in sparse lineup columns to 0
        elif col in sparse_cols:
            df[col] = df[col].fillna(0)

    # fix free throw columns on technicals
    df.loc[df.is_tech_fta, ['fta_num', 'tot_fta']] = 1

    # fill in NaN's/fix off_team and def_team columns
    df.off_team.fillna(method='bfill', inplace=True)
    df.def_team.fillna(method='bfill', inplace=True)
    df.off_team.fillna(method='ffill', inplace=True)
    df.def_team.fillna(method='ffill', inplace=True)

    return df
def clean_features(df):
    """Fixes up columns of the passed DataFrame, such as casting T/F columns to
    boolean and filling in NaNs for team and opp.

    :param df: DataFrame of play-by-play data.
    :returns: Dataframe with cleaned columns.
    """
    df = pd.DataFrame(df)

    bool_vals = set([True, False, None, np.nan])
    sparse_cols = sparse_lineup_cols(df)
    for col in df:

        # make indicator columns boolean type (and fill in NaNs)
        if set(df[col].unique()[:5]) <= bool_vals:
            df[col] = (df[col] == True)

        # fill NaN's in sparse lineup columns to 0
        elif col in sparse_cols:
            df[col] = df[col].fillna(0)

    # fix free throw columns on technicals
    df.loc[df.is_tech_fta, ['fta_num', 'tot_fta']] = 1

    # fill in NaN's/fix off_team and def_team columns
    df.off_team.fillna(method='bfill', inplace=True)
    df.def_team.fillna(method='bfill', inplace=True)
    df.off_team.fillna(method='ffill', inplace=True)
    df.def_team.fillna(method='ffill', inplace=True)

    return df
def clean_features ( df ) : df = pd . DataFrame ( df ) bool_vals = set ( [ True , False , None , np . nan ] ) sparse_cols = sparse_lineup_cols ( df ) for col in df : # make indicator columns boolean type (and fill in NaNs) if set ( df [ col ] . unique ( ) [ : 5 ] ) <= bool_vals : df [ col ] = ( df [ col ] == True ) # fill NaN's in sparse lineup columns to 0 elif col in sparse_cols : df [ col ] = df [ col ] . fillna ( 0 ) # fix free throw columns on technicals df . loc [ df . is_tech_fta , [ 'fta_num' , 'tot_fta' ] ] = 1 # fill in NaN's/fix off_team and def_team columns df . off_team . fillna ( method = 'bfill' , inplace = True ) df . def_team . fillna ( method = 'bfill' , inplace = True ) df . off_team . fillna ( method = 'ffill' , inplace = True ) df . def_team . fillna ( method = 'ffill' , inplace = True ) return df
Fixes up columns of the passed DataFrame, such as casting T/F columns to
    boolean and filling in NaNs for team and opp.

    :param df: DataFrame of play-by-play data.
    :returns: Dataframe with cleaned columns.
Fixes up columns of the passed DataFrame such as casting T / F columns to boolean and filling in NaNs for team and opp .