import string


def scrub_names(df, comments_col='comments', name_token='<name>'):
    """
    For each guest, replace the guest's name with a generic '<name>' token. Tokens to replace for each guest are
    specfied in the 'name_filter' column of the input CSV file.

    :param df: guest dataframe with a column containing concatenated comments (a string)
    :return: same dataframe with names substituted in the comments
    """
    if comments_col not in df:
        raise KeyError("Dataframe must have a 'comments' column")

    for i, row in df.iterrows():
        # look for tokens specified in CSV, plus those tokens including some basic punctuation
        raw_names = [row['guest'].lower()] + row['name_filter'].split(', ')
        names = raw_names + [x + "'s" for x in raw_names]
        names += [x + y for y in string.punctuation for x in raw_names]
        names += [y + x for y in string.punctuation for x in raw_names]

        comments = row[comments_col]
        scrubbed_comments = comments.split(' ')
        scrubbed_comments = [name_token if x.lower() in names else x for x in scrubbed_comments]
        scrubbed_comments = ' '.join(scrubbed_comments)

        df.loc[i, comments_col] = scrubbed_comments

    return df