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:
for col in [EPRI,LMTR,LastR]:
myData[col] = round(myData[col]/1000,0).astype(int).map("{:,}".format)
CodePudding user response:
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()]