0

I have the following block of code:

idatual=txt2['pvSystems'][x]['pvSystemId']
nomedocliente = txt2['pvSystems'][x]['name']
nomesclientes = pd.read_excel(file_loc, sheet_name="MONITORAMENTO", index_col=None, na_values=['NA'], usecols = "B")
y=0
print("name of the client: " + str(nomedocliente))
while y < len(nomesclientes):
    print("name of the client on the sheets: " + nomesclientes.iloc[y][0])
    if nomedocliente == nomesclientes.iloc[y][0]:

So, a few things worth noticing:

  • "nomedocliente",the first element on the comparison, is taken from a response originated by a request.
  • The idea is to compare "nomedocliente" to the values of a column from an Excel sheet, if the value is equal, we trigger an action.
  • Both values are strings.
  • The code works for the most values, but it doesn't work on very specific cases, like:

Case 1:

    name of the client: Pice e Cia
    name of the client on the sheets: Pice e Cia

Case 2:

    name of the client: Iolanda Saraiva Irecê
    name of the client on the sheets: Iolanda Saraiva Irecê
  • Problem cases don't have a pattern on them.

  • I've assured that those strings are equal, since they trigger if statements on other cases.

Any ideas ?

EDIT:

I've followed the solution that it was linked to this question and it did NOT help. I've changed the code to normalize the strings:

Older line:

if nomedocliente == nomesclientes.iloc[y][0]:

New Line:

 if (unicodedata.normalize('NFC',str(nomedocliente)) == unicodedata.normalize('NFC',str(nomesclientes.iloc[y][0]))):

The problem was not solved.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
artursouza
  • 23
  • 5
  • The problem occurs because strings that appear identical can sometimes have different actual Unicode code points in them, thanks to how Unicode works. See the linked duplicate for more information. – Karl Knechtel Nov 18 '21 at 14:19
  • If that's the case, shouldn't these strings never trigger a if statement ? When I copy and paste those strings on another if statement they work. They specifically don't work inside this loop – artursouza Nov 18 '21 at 14:22
  • Have you tried trimming whitespaces? Have you tried to compare bytes of your problem cases? `str.encode(my_str)` – wp78de Dec 01 '21 at 01:12
  • Hello ! I've solved this question befor it got reopened. The trimm + the normalizing solved the problem for me. – artursouza Dec 06 '21 at 14:51

0 Answers0