Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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\lyReload.py", 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\generic.py", line 5575, in __getattr__
    return object.__getattribute__(self, name)

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

Original code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Test:

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()]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading