[解决pandas问题]AttributeError: type object ‘object‘ has no attribute ‘dtype‘

最近写文档时,想用现成的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)

[解决pandas问题]AttributeError: type object ‘object‘ has no attribute ‘dtype‘_第1张图片
报错代码是:

test2 = pd.DataFrame(columns=table.columns)
print(test2)

解决办法:

test2 = pd.DataFrame(columns=table.columns,dtype=object)
print(test2)

在这里插入图片描述
问题原因:
可能跟pandas版本有关,本次所用pandas版本为0.25.3
后续再出现类似问题统一整理

你可能感兴趣的:(Pandas,pandas,python,数据分析)