TypeError:write()中不支持的类型

时间:2020-12-02 15:49:40

So i am reading a .xlsx file and i need to check how many variables in the xlsx file belong to each datatype in pandas and finally export it to excel.

所以我正在读一个.xlsx文件,我需要检查xlsx文件中有多少变量属于pandas中的每个数据类型,最后将其导出到excel。

So here is the code :

所以这是代码:

sheet = pd.read_excel(r"D:\Users\850034535\AnacondaProjects\Jupyter Project\Sample.xlsx",sheetname=2)
alldtypes = sheet.dtypes.value_counts()
alldtypes_df = list_of_all_variables.to_frame()
alldtypes_df.to_excel('123.xlsx')

This code gives an error: " TypeError: float() argument must be a string or a number, not 'numpy.dtype' "

此代码给出错误:“TypeError:float()参数必须是字符串或数字,而不是'numpy.dtype'”

So then i converted the dataframe to str type, so now an additional line of code was added :

那么我将数据帧转换为str类型,所以现在增加了一行代码:

 alldtypes_df = alldtypes_df.applymap(str)

But still it is showing me the same error and the error given in the title.

但它仍然向我显示相同的错误和标题中给出的错误。

Any suggestions would be much appreciated.

任何建议将不胜感激。

1 个解决方案

#1


1  

It seems need convert index to strings:

似乎需要将索引转换为字符串:

alldtypes_df.index = alldtypes_df.index.astype(str)

#1


1  

It seems need convert index to strings:

似乎需要将索引转换为字符串:

alldtypes_df.index = alldtypes_df.index.astype(str)