在Python中,有没有有效的方法从单元格范围创建列表?

在Python中,有没有有效的方法从单元格范围创建列表?,python,excel,row,cells,Python,Excel,Row,Cells,我有一个Excel文件,我有一些参数,我需要在特定的单元格范围内返回,但不同的行 def get_list(row, start, stop): arr = list[start:stop] #and somewhere here I need to iterate throgh row because I store row separately. 有什么建议吗?谢谢 您可以传递以下函数的范围。我在这里使用xlrd import xlrd def excel_reader(exce

我有一个Excel文件,我有一些参数,我需要在特定的单元格范围内返回,但不同的行

def get_list(row, start, stop):
    arr = list[start:stop] #and somewhere here I need to iterate throgh row because I store row separately.

有什么建议吗?谢谢

您可以传递以下函数的范围。我在这里使用xlrd

import xlrd

def excel_reader(excel_name):
    wb = xlrd.open_workbook(excel_name)
    sh = wb.sheet_by_index(0)
    for i in range(sh.nrows):
        if i > 0:
            cell_value_class = int(sh.cell_value(i, 0))
            cell_value_id = int(sh.cell_value(i, 1))
            DataList[cell_value_class] = cell_value_id

您可以使用
xlswriter
,您可以指定每个单元格。我只需要使用范围并遍历行,我不想手动访问每个单元格。您能告诉我吗?
pandas
软件包允许您使用
csv
.xls
轻松操作文件,使用
csv
您将获得整行,如果您使用正常的切片,非常感谢!效果很好。