Python xlrd 模块 [英] Python xlrd module

查看:26
本文介绍了Python xlrd 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据XLRD模块的文档,

According to the documentation of the XLRD module,

 row_values(rowx, start_colx=0, end_colx=None)

返回给定行中单元格值的一部分."

"Returns a slice of the values of the cells in the given row."

并给出以下python代码:

And given the following python code:

import xlrd
wb=xlrd.open_workbook("xl1.xlsx")
sh = wb.sheet_by_index(0)
for rownum in range(sh.nrows):
    print sh.row_values(rownum) 

输出为:

 [12.0, u'test.0']
 [34.0, u'te.st']
 [u'test123', u'12.test']

并且exel文件包含以下数据:

and the exel file holds the following data:

12.0、test.0、34.0、test、test123、12.test

12.0 , test.0 , 34.0 , te.st , test123 , 12.test

那么,根据输出,我得到什么类型的数据结构作为一行?它不是元组,(因为在打印元组类型时,没有 u' 作为字符串的前缀), u' 的含义是什么?而且它就像我们在数据结构中有两种类型的数据 - int 和非 int".这是真的吗?我在文档中找不到任何关于此的信息.谢谢!

So, what type of data structure do I get as a line according to the output? Its not a tuple, (becasue when printing a tuple type, there is no u' as a prefix to a string), and what is the meaning of the u' ? And also its like we have two types of data in the data structure - int and "non int". Is it true? I could not find any information about this in the documentation. Thanks!

推荐答案

row_values 返回具有适当数据类型的单元格值列表.列表中每一项的数据类型取决于源excel文件中的单元格类型.

row_values returns a list of cell values with appropriate data types. Data type of each item in the list depends on the cell type in the source excel file.

可能有只有 stringfloatint 数据类型的项目,请参阅此 映射表(在那里找到 Cell 的文档)了解更多信息.

There could be items with only string, float and int data types, see this mapping table (find there docs for Cell) for more info.

u 只是表示这是一个 unicode 字符串.文档 解释得很好.

u just means that this is a unicode string. Documentation explains it pretty well.

希望有所帮助.

这篇关于Python xlrd 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆