最近写文档时,想用现成的DataFrame数组生成一个空表头时报此错:
AttributeError: type object 'object' has no attribute 'dtype'
现成的DataFrame如下:
file_path = r'demo22.xlsx'
table = pd.read_excel(file_path)
print('table')
print(table)
报错代码是:
test2 = pd.DataFrame(columns=table.columns)
print(test2)
解决办法:
test2 = pd.DataFrame(columns=table.columns,dtype=object)
print(test2)
问题原因:
可能跟pandas版本有关,本次所用pandas版本为0.25.3
后续再出现类似问题统一整理