我的 excel 数据如下所示:
A B C
1 123 534 576
2 456 745 345
3 234 765 285
在另一个 Excel 电子表格中,我的数据可能如下所示:
B C A
1 123 534 576
2 456 745 345
3 234 765 285
如何从两个电子表格中提取 C 列的内容?
我的代码如下:
#Open the workbook
ow = xlrd.open_workbook('export.xlsx').sheet_by_index(0)
#Store column 3's data inside an array
ips = ow.col_values(2, 1)
我想要更多类似的东西:
ips = ow.col_values(C, 1)
我怎样才能实现上述目标?
最佳答案
由于我有两个不同的电子表格,并且我想要的数据位于两个单独的行中,因此我必须按名称搜索第一行,直到找到它,然后提取该列。
我是这样做的:
ow = xlrd.open_workbook('export.xlsx').sheet_by_index(0)
for x in range (0, 20):
try:
if ow.cell_value(0, x) == "IP Address":
print "found it!"
ips = ow.col_values(x, 1)
break
except IndexError:
continue
关于python - 如何按列名提取excel数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43221330/