|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import xlrdworkbook = xlrd.open_workbook(datafile)sheet = workbook.sheet_by_index(0)data = [[sheet.cell_value(row,col) for col in xrange(sheet.ncols)] for row in xrange(sheet.nrows)]#sheet 的row index和 col index 都是从0开始的coast = sheet.col_values(1,start_rowx=1,end_rowx=None)# coast 是一个列表 行数范围[start,end)#时间处理exceltime = '1/1/13 1:00'xlrd.xldate_as_tuple(exceltime,0)#结果为 (2013,1,1,1,0,0)精确到秒 |
利用xlrd处理Excel文件
解读Excel数据处理与时间解析
最新推荐文章于 2024-08-26 22:58:59 发布
本文详细介绍了如何使用Python的xlrd库打开并读取Excel文件中的数据,包括使用sheet_by_index()方法选择工作表,cell_value()方法获取单元格值,并展示了如何处理Excel时间格式,将日期和时间转换为Python的datetime对象。通过实例演示了从指定列提取数据以及时间处理的方法。
2103

被折叠的 条评论
为什么被折叠?



