我正在尝试比较来自两个不同数据集的多组数据。我使用csv.DictReader引用了每个csv。然后我创建了一个函数处理程序来处理每个函数。每个函数处理一组不同的数据,正在使用的两个数据集被分解为一组函数。
以下是导致错误的函数,并且没有keyerror,因为它引用的列名没有问题。然后每个函数由secMastHandler()函数处理,我将每个函数引用为 inputData = secMastHandler()。我可以将每个函数的数据作为列表inputData [n]引用,它可以正常压缩zip(inputData [a],inputData [b])并执行条件(如果行[0] == line [1] :) 。
但是zip()和后续if语句中的两个以上元素不起作用并获取有关键错误的错误消息。在这个例子中,这似乎是一个奇怪的错误。所以真正的问题是如何在同一个if语句中比较这些多个数据集?
def frfSecDict(): ## function handling the frfpost data
## from the section file data set
import csv
reader = csv.DictReader(outData)
for row in reader:
frfpost = str(row['FRFPOST']) ## Line 61. There is not keyError here
frfpostFlt = round(float(frfpost),3)
yield frfpostFlt
line 61, in frfSecDict
frfpost = str(row['FRFPOST'])
KeyError: 'FRFPOST'
def secMastHandler(): ## handler function for functions handling data from
## multiple data sources
gen0 = corrSecDict()
gen1 = svySecDict() ## this is inputData[1]
gen2 = frfSecDict() ## this is inputData[2]
gen3 = trfSecDict()
gen4 = corrMastDict()
gen5 = svyMastDict() ## this is inputData[5]
gen6 = frfMastDict() ## this is inputData[6]
gen7 = trfMastDict()
return gen0,gen1,gen2,gen3,\
gen4,gen5,gen6,gen7
def SecMastPrinter(): ## this function should yield output from multiple
## datasets based upon the conditions from
## the zipped inputData datasets.
inputData = secMastHandler()
for line in zip(inputData[1],inputData[5],\
inputData[2],inputData[6]): ## doesnt seem to like this
## second line in the zip
if line[0] == line[1] and line[2] == line[3]: ## this not possible?
output = line[:]
yield output
def frfSecMastPrinter():
inputData = secMastHandler()
for line in zip(inputData[2],inputData[6]): ## but just a one line
## zip works just fine
if line[0] == line[1]:
output = line[:]
yield output