InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided ('td�') is not a valid name

Hi! Can somebody help me?

I have an HTML table:

  • When displaying the table, after ONLY activating “add_flag”, it works fine.
  • When displaying the table, after ONLY activating “short_name”, it works fine.
  • But if I activate both, it doesn’t work. And I get this error:

InvalidCharacterError: Failed to execute 'createElement' on 'Document': The tag name provided ('td�') is not a valid name.

Anyone as any idea why? Here’s the full code:

def short_name(player):
    name = str(player['Player']).split()
    if len(name)>1:
        return name[0]+' '+name[-1]
    else:
        return name[0]

players['Player'] = players.apply(short_name, axis=1)


flag = {dictionary of the form "Name": "Flag Emoji" }
def add_flag(player):
    country = str(player['Country']).strip()
    country_plus_flag = flag.get(country, " ")
    return player['Player']+' '+country_plus_flag

players['Player'] = players.apply(add_flag, axis=1)

Thank you!