我在一个项目上工作,我有两个csv文件,我已经转换成二维列表。我有一个列表1,在某个区域内有一定数量的钻孔,还有一个列表2,它有相应的多个值来计算平均值、最小值和最大值。我有问题,因为我认为功能是:
不跳过列表中值的标题,因此不获取整数
可能连比较这两个列表都没有,因为我一直被困在步骤1中
到目前为止,我得到的是:
def height(bReader, dataList):
print "Height function ran, but no result"
# bReader is bores inside polygon
# dataList BORE_DATA.csv as 2D list
avgHeight = 0
minN = 9e99
maxPh = 0
numCount = 0
for row in bReader:
for row2 in dataList:
if row[0] == row2[0]:
if row2[1] == '':
if row2[1][0] == '<':
row2[1] = row2[1][:1]
avgHeight += row2[4]
numCount += 1
print row2[4]
# Checks the minimum values of Nitrogen
if row2[6] < minN:
minN = row2[6]
# Checks the maximum values of Phosphorous
if row2[5] < maxPh:
maxPh = row2[5]
if lastID != row2[0]:
# Checks for final value before moving to next bore
aveHeight = avgHeight / numCount
print row[0]
print "Average Water Level" + aveHeight
print "Minimum Nitrogen" + minN
print "Maximum Phosphorous" + maxPh
avgHeight = 0
minN = 9e99
maxPh = 0
numCount = 0
lastID = row[0]
这是回溯错误:
Traceback (most recent call last):
File "C:\Users\Lounge\Desktop\V2\ReRun V2.py", line 39, in main
height(levelsList, bdataList)
File "C:\Users\Lounge\Desktop\V2\ReRun V2.py", line 263, in height
for row in bReader:
TypeError: 'function' object is not iterable
样本数据:
列表1数据
REFERENCE EASTING NORTHING TOC ELEVATION (m)
61610628 384835 6489341 20.24
列表2数据
BORE REF NR BORE NAME SAMPLE DATE water level (m) TDSolids (mg/L) pH N (mg/L) P (mg/L)
61610628 JP20B 23/06/2000 3.71 430 8.8 0.28 0.007
61610628 JP20B 27/10/2000 3.18 610 7.2 1.3 0.019
我对程序做了一些修改使它运行起来。要考虑的要点是:
row2[3]
而不是row2[4]
if row2[1] == '':
的逻辑,因为它看起来是多余的。你知道吗以下是修订后的代码:
产生以下输出:
希望这能为你解决问题。你知道吗
从跟踪来看,您传递给函数的参数似乎不是一个列表,而是一个函数。调用
height(...)
的代码就是错误所在。你知道吗很抱歉没有发表评论,我没有这样做的声誉。你知道吗
相关问题 更多 >
编程相关推荐