How to create a new column based on two other columns in Pandas?
You can try something like this to get a new dataframe that has pairs of (EventID, TeamCount):

event_id_team_count = data.groupby('EventID').agg({'TeamID': lambda x: x.nunique()})
event_id_team_count.rename(columns={"TeamID": "TeamCount"}, inplace=True)


If you want to have this new column in the original dataframe, all you need to do is to join the original dataframe with the one you have just created:

data = data.join(other=event_id_team_count, on="EventID")