0

我有一个 Excel 数据集:

"id","value","name"
  1  , 10,    "cat"
  2  , 20,    "fish"

在 Python 中:

import xlrd

col1 = "id"
col2 = "value"
col3 = "name"
wb = xlrd.open_workbook("file.xls")
sh = wb.sheet_by_index(0)

result = sh.someMethod((col1,col3))?????

有没有一种方法可以按名称返回列?

print result
[[1,"cat"],[2,"fish"]]
4

1 回答 1

2

col_slice 可能是合适的,例如:

zip(sh.col_slice(0,1),sh.col_slice(2,1))
于 2012-11-09T04:59:07.257 回答