我对python比较陌生,我试图找到包含值“3275”的单元格,这里是“newELA”。此值位于电子表格的顶行,是标题。这就是我一直在尝试的:
loc=("/Volumes/Project/Andes_Glacier_Inventory.xlsx")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(1)
headers = sheet.row(0)[3:]
a = np.array(sheet.row_values(1,3))
value = 501
ELA = headers[np.argmax(a * (a < value))]
print ("The ELA is", ELA.value)
changeinELA = 100
value1 = changeinELA
value2 = ELA.value
newELA = float(value1) + float(value2)
print ("The new ELA is", newELA)
b = np.where (np.array(headers) == newELA)
print (b)
我得到的结果是,我甚至不明白
^{pr2}$
您得到的是一个空数组,因为您的
headers
中没有与您的newELA
值相等的内容。在检查你的数据。只需考虑一下您可能遇到的问题:如果存在浮点错误,可以执行以下操作:
您可以看到How does python numpy where work?。值“3275”是一个字符串。上 另一方面,你有一个整数数组,newELA是float。您必须决定headers数组是哪个数据类型,并且它应该与newELA变量相同。例如
输出
^{pr2}$相关问题 更多 >
编程相关推荐