所以我正在读取一个.xlsx文件,我需要检查 xlsx 文件中有多少变量属于熊猫中的每种数据类型,最后将其导出到 excel。
所以这是代码:
sheet = pd.read_excel(r"D:Users850034535AnacondaProjectsJupyter ProjectSample.xlsx",sheetname=2)
alldtypes = sheet.dtypes.value_counts()
alldtypes_df = list_of_all_variables.to_frame()
alldtypes_df.to_excel('123.xlsx')
这段代码给出一个错误:"TypeError: float(( 参数必须是字符串或数字,而不是 'numpy.dtype' ">
所以然后我把数据帧转换为str类型,所以现在添加了一行额外的代码:
alldtypes_df = alldtypes_df.applymap(str)
但它仍然向我显示相同的错误和标题中给出的错误。
任何建议将不胜感激。
似乎
需要将索引转换为string
s:
alldtypes_df.index = alldtypes_df.index.astype(str)