将两个csv中的数据整合。
a = [['id', 'info', 'ha'], ['1', '11','0.1']]
b = [['id', 'info', 'na'], ['1', '11','0.2',], ['2', '22','0.3']]
sheet = pe.Sheet(a)
sheet.save_as('num/a.csv')
sheet = pe.Sheet(b)
sheet.save_as('num/b.csv')
new_dict = {}
prediction = list()
with open('num/a.csv','r') as fp:
data = csv.reader(fp, delimiter=',')
for row in data:
new_dict[row[0]]=[row[0], row[1],row[2],'null','null','null','null','null']
with open('num/b.csv','r') as fp:
data = csv.reader(fp, delimiter=',')
for row in data:
if row[0] in new_dict:
new_dict[row[0]][3] = row[-1]
else:
new_dict[row[0]]=[row[0],row[1],row[2],'null','null','null','null','null']
new_dict[row[0]][3] = row[-1]
for key in new_dict:
prediction.append(new_dict[key])
sheet = pe.Sheet(prediction)
sheet.save_as('class_not_train.csv')