sportsref/nfl/pbp.py
def expand_details(df, detailCol='detail'):
    """Expands the details column of the given dataframe and returns the
    resulting DataFrame.

    :df: The input DataFrame.
    :detailCol: The detail column name.
    :returns: Returns DataFrame with new columns from pbp parsing.
    """
    df = copy.deepcopy(df)
    df['detail'] = df[detailCol]
    dicts = [sportsref.nfl.pbp.parse_play_details(detail) for detail in df['detail'].values]
    # clean up unmatched details
    cols = {c for d in dicts if d for c in d.keys()}
    blankEntry = {c: np.nan for c in cols}
    newDicts = [d if d else blankEntry for d in dicts]
    # get details DataFrame and merge it with original to create main DataFrame
    details = pd.DataFrame(newDicts)
    df = pd.merge(df, details, left_index=True, right_index=True)
    # add isError column
    errors = [i for i, d in enumerate(dicts) if d is None]
    df['isError'] = False
    df.loc[errors, 'isError'] = True
    # fill in some NaN's necessary for _clean_features
    df.loc[0, 'qtr_time_remain'] = '15:00'
    df.qtr_time_remain.fillna(method='bfill', inplace=True)
    df.qtr_time_remain.fillna(
        pd.Series(np.where(df.quarter == 4, '0:00', '15:00')), inplace=True
    )
    # use _clean_features to clean up and add columns
    new_df = df.apply(_clean_features, axis=1)
    return new_df
def expand_details(df, detailCol='detail'):
    df = copy.deepcopy(df)
    df['detail'] = df[detailCol]
    dicts = [sportsref.nfl.pbp.parse_play_details(detail) for detail in df['detail'].values]
    # clean up unmatched details
    cols = {c for d in dicts if d for c in d.keys()}
    blankEntry = {c: np.nan for c in cols}
    newDicts = [d if d else blankEntry for d in dicts]
    # get details DataFrame and merge it with original to create main DataFrame
    details = pd.DataFrame(newDicts)
    df = pd.merge(df, details, left_index=True, right_index=True)
    # add isError column
    errors = [i for i, d in enumerate(dicts) if d is None]
    df['isError'] = False
    df.loc[errors, 'isError'] = True
    # fill in some NaN's necessary for _clean_features
    df.loc[0, 'qtr_time_remain'] = '15:00'
    df.qtr_time_remain.fillna(method='bfill', inplace=True)
    df.qtr_time_remain.fillna(
        pd.Series(np.where(df.quarter == 4, '0:00', '15:00')), inplace=True
    )
    # use _clean_features to clean up and add columns
    new_df = df.apply(_clean_features, axis=1)
    return new_df
def expand_details ( df , detailCol = 'detail' ) : df = copy . deepcopy ( df ) df [ 'detail' ] = df [ detailCol ] dicts = [ sportsref . nfl . pbp . parse_play_details ( detail ) for detail in df [ 'detail' ] . values ] # clean up unmatched details cols = { c for d in dicts if d for c in d . keys ( ) } blankEntry = { c : np . nan for c in cols } newDicts = [ d if d else blankEntry for d in dicts ] # get details DataFrame and merge it with original to create main DataFrame details = pd . DataFrame ( newDicts ) df = pd . merge ( df , details , left_index = True , right_index = True ) # add isError column errors = [ i for i , d in enumerate ( dicts ) if d is None ] df [ 'isError' ] = False df . loc [ errors , 'isError' ] = True # fill in some NaN's necessary for _clean_features df . loc [ 0 , 'qtr_time_remain' ] = '15:00' df . qtr_time_remain . fillna ( method = 'bfill' , inplace = True ) df . qtr_time_remain . fillna ( pd . Series ( np . where ( df . quarter == 4 , '0:00' , '15:00' ) ) , inplace = True ) # use _clean_features to clean up and add columns new_df = df . apply ( _clean_features , axis = 1 ) return new_df
Expands the details column of the given dataframe and returns the
    resulting DataFrame.

    :df: The input DataFrame.
    :detailCol: The detail column name.
    :returns: Returns DataFrame with new columns from pbp parsing.
Expands the details column of the given dataframe and returns the resulting DataFrame .