使用xlrd-Python读取范围内的行数

使用xlrd-Python读取范围内的行数,python,xlrd,Python,Xlrd,我想读取一个范围内的行数。我有一个有很多行的文件。我想知道列范围内的行数,比如从a列到D列 workbook = xlrd.open_workbook(file) sheet = workbook.sheet_by_index(0) sheet.nrows[0:4] #I want to know the number of rows within that range, or "A{}:D{}" 如果有人知道这样做的方法,请帮助我。谢谢大家! 您可以遍历列。。。 使用循环: for col_

我想读取一个范围内的行数。我有一个有很多行的文件。我想知道列范围内的行数,比如从a列到D列

workbook = xlrd.open_workbook(file)
sheet = workbook.sheet_by_index(0)
sheet.nrows[0:4] #I want to know the number of rows within that range, or "A{}:D{}"

如果有人知道这样做的方法,请帮助我。谢谢大家!

您可以遍历列。。。 使用循环:

for col_idx in range(0, num_cols): # Iterate through columns cell_obj = xl_sheet.cell(row_idx, col_idx) # Get cell object by row, col 对于范围(0,num_cols)中的col_idx:#遍历列 cell_obj=xl_sheet.cell(row_idx,col_idx)#按行获取cell对象,col
使用xlrd并没有什么问题,这也是我首先使用的。但是,我建议使用该库,因为它在整个python社区中使用得更多

import pandas

dataframe = pandas.read_excel(file, usecols='A:D')
print(len(dataframe))

非常感谢。我不知道。syntaxis看起来更好,更易于数据操作。