def cols_to_count(df, group, columns):
    """Count the number of column values when grouping by another column and return new columns in original dataframe.

    Args:
        df: Pandas DataFrame.
        group: Column name to groupby
        columns: Columns to count.

    Returns:
        Original DataFrame with new columns containing prefixed count values.

    """

    for col in columns:
        df['count_' + col + '_by_' + group] = df.groupby(group)[col].transform('count')
    return df