【发布时间】:2018-08-20 09:56:06
【问题描述】:
所以我正在读取一个.xlsx 文件,我需要检查xlsx 文件中有多少变量属于pandas 中的每个数据类型,最后将其导出到excel。
所以这里是代码:
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')
此代码给出错误:“ TypeError: float() argument must be a string or a number, not 'numpy.dtype'”
然后我将数据帧转换为 str 类型,所以现在添加了额外的代码行:
alldtypes_df = alldtypes_df.applymap(str)
但它仍然向我显示相同的错误和标题中给出的错误。
任何建议将不胜感激。
【问题讨论】:
标签: python excel pandas dataframe python-applymap