希望有人能在我收到的AttributeError上提供建议,因为我不确定我的代码编写方式有什么问题。我见过其他关于"'DataFrame‘对象没有属性“的帖子,但是它不适用于这个场景。使用Python的map()函数在所有行和指定列之间迭代和应用相同的格式,但是map()似乎是问题所在。有没有其他办法?
错误消息:
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'
原始代码:
for col in [EPRI,LMTR,LastR]:
myData[col] = round(myData[col]/1000,0).astype(int).map("{:,}".format)
发布于 2022-05-10 12:31:56
问题是重复的列名。因此,整数序列(一列),您的代码返回所有列的同名。
测试:
for col in [EPRI,LMTR,LastR]:
print (myData[col])
解决方案是deduplicated columns names或删除重复的列名:
myData = myData.loc[:, ~myData.columns.duplicated()]
https://stackoverflow.com/questions/72186224
复制相似问题