You're iterating on the prediction1 with "result" but you write the whole prediction1 on every row:
for result in prediction1:
writer.writerow({'PassengerId':'test','Survived':result})
You are already doing that. You first define the columns and their order (fieldnames
) and then when you call writerow()
, you give it a dict with the value for each column and csv.DictWriter
puts them in the right order.
You could write:
for result in prediction1:
writer.writerow({'Survived':result, 'PassengerId':'test'})
And have the same exact result.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…