1

I have been trying to use a Pandas Dataframe in Python 3 to find a specific id matching a name from a CSV file. The API I am reading from gives me the name António, along with other names, the way I need it to with the accent in a column called "first". I have an array of names that won't necessarily have all of the accents I need to match. This program seems to work for every name I try except for the ones that have different values for accented characters.

import pandas as pd

nameArray=[Antonio,Matt,Mark,Raul]
playersUrl = 'https://www.FakeSite.com/players'
playerData = pd.read_csv(playersUrl, names=["PLAYERID", "FIRSTNAME"]

for first, playerid in zip(playerData["FIRSTNAME"],playerData["PLAYERID"]):
    for i in len(nameArray):
        testName = nameArray[i]    
        if first == testName:
            return playerid
Dan
  • 173
  • 2
  • 9

1 Answers1

1

If you want to do a compare without diacritics, see previous SO post here:

Unidecode is the correct answer for this. It transliterates any unicode string into the closest possible representation in ascii text.

Community
  • 1
  • 1
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135