'Python list comparing implementation and error

The program is supposed to take the rows in column [newAssetCode] and compare them to the rows in column ['allAssetCodes'] to then find the assets in [newAssetCode] that already exist in ['allAssetCodes']. The program will then count how many times the assets exist in ['allAssetCodes']. for example if If ['allAssetCodes'] contains 'XYZ','XYZ1', 'XYZ2' it will count that and then add a digit to that count and append that number in a new list creating 'XYZ3'. my question is did I implement this correctly? and Also I do have an error. enter image description here

'''

from itertools import count
import pandas as pd
import openpyxl
from csv import reader

data = pd.read_excel('Codes.xlsx')
new_assets =  data['newAssetCode'].tolist()
allAssetCodes = data['allAssetCodes'].tolist()

print(len(new_assets))
print(len(allAssetCodes))

assets_real = list()
for asset in new_assets:
    if not isinstance(asset,str):
        continue
    if asset not in allAssetCodes:
        assets_real.append(asset)
        continue
    existing = [exasset for exasset in allAssetCodes if exasset.startswith(asset)]
    assets_real.append(f'{asset}{len(existing)+1}')

print(assets_real)
print(existing)

'''



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source