def append_gw_teams(df, df_match):
    """
    Count the number of teams playing in a single gameweek
    :param df: Input DataFrame (must contain 'player_id', 'gw' columns)
    :param df: Match DataFrame
    :returns: Input DataFrame with 'gw_teams_ft' column appended
    """
    df = df.copy()
    df_teams = (df_match.groupby('gw')['team_id'].nunique()
                        .reset_index()
                        .rename(columns={'team_id':'gw_teams_ft'}))

    return df.merge(df_teams, on='gw').sort_values(['player_id', 'gw'])