我有一个简单的 CSV 数据文件,它有两行,即Object_Id和 的VALUE每个Object ID索引在另一行 ( VALUE)中具有相同索引的对应值。我的目的是读取这些索引并使用预期数据验证这些数据。
我能够读取 csv 文件,但不确定如何验证数据。这是 csv 文件的一部分:
Obj ID, Value, Time Stamp
13, 41.0, 2018-09-10 23:05:30
14, 14.0, 2018-09-10 23:05:20
13, 41.0, 2018-09-10 23:05:20
14, 14.0, 2018-09-10 23:05:09
这是我正在尝试的代码:
import csv
with open('testoutfile1.csv', 'r') as csvfile:
reader = csv.reader (csvfile, delimiter=';', quotechar='|')
observed_output=[]
expected_output=[]
for row in reader:
#print('; '.join(row))
observed_output = {row[0]:row[1]}
print(observed_output)
expected_output= {'Obj ID': 'Value','13':'41.0', '14':'14.0'}
print(expected_output)
for key in expected_output:
if key in observed_output:
print (key)
print (observed_output[key])
print (expected_output [key])
if (observed_output[key])== (expected_output [key]):
print ("Test Passed")
elif (observed_output[key])!= (expected_output [key]):
print ("Test Failed")
这是我收到的输出,肯定缺少与其他条目/条目匹配的输出。你能评论吗?
{'Obj ID': 'Value'}
{'13': '41.0'}
{'14': '14.0'}
{'13': '41.0'}
{'14': '14.0'}
{'Obj ID': 'Value', '13': '41.0', '14': '14.0'}
14
14.0
14.0
Test Passed
素胚勾勒不出你
相关分类