AttributeError when applying map() for formatting

Hoping someone can advise on the AttributeError I’m receiving, as I’m not sure what is wrong with the way my code is written. I’ve seen other posts dealing with "’DataFrame’ object has no attribute", but it wasn’t applicable to this scenario. Using Python’s map() function to iterate and apply the same formatting across all rows and specified columns, but the map() seems to be the issue. Is there any alternative approach?

Error message:

  File "Z:\Report\PythonScripts\reporting\templates\", line 70, in getlyReloadTemplate
    myData[col] = round(myData[col]/1000,0).astype(int).map("{:,}".format)

  File "C:\Program Files\Anaconda3\lib\site-packages\pandas\core\", line 5575, in __getattr__
    return object.__getattribute__(self, name)

AttributeError: 'DataFrame' object has no attribute 'map'

Original code:

for col in [EPRI,LMTR,LastR]:
           myData[col] = round(myData[col]/1000,0).astype(int).map("{:,}".format) 

>Solution :

Problem is duplicated columns names. So intead Series (one column) your code return all columns with same name.


for col in [EPRI,LMTR,LastR]:
    print (myData[col])

Solution is deduplicated columns names or remove duplicated columns names:

myData = myData.loc[:, ~myData.columns.duplicated()]

Leave a Reply