Data = pd.ExcelFile(filename[0])
ncols = Data.book.sheet_by_index(0).ncols #class book google it
Data_df = Data.parse(0, converters={i : str for i in range(ncols-1)}, encoding="utf-8")
Dict of functions for converting values in certain columns. Keys can either be integers or column labels, values are functions that take one input argument, the Excel cell content, and return the transformed content.
我想这段文字前面有
ExcelFile
类描述为here, in the Pandas documentation。^{converters
参数在最后一个链接中描述:第2行中访问的
book
对象是xlrd
包的一部分,它是panda
用来读取Excel文件的底层实现。它被记录在here和sheet_by_index
方法here中(尽管它们只是做了您可能期望的事情);Sheet
中的ncols
字段记录为here,它只返回工作表中的列数,忽略后面的空列简而言之,
range(ncols-1)
将生成除最后一列之外的所有列的索引,因此转换器字典{i : str for i in range(ncols-1)}
的作用是将除最后一列之外的每一列都视为简单字符串,而不是试图解析每个单元格以确定其数据类型相关问题 更多 >
编程相关推荐