我正在参加 Kaggle Titanic 初学者比赛。我通常在 Spyder IDE 中工作,但遇到了一个奇怪的问题。预期的输出应该是 418 行。当我从终端运行脚本时,我得到的输出是 418 行(如预期的那样)。当我在 Spyder IDE 中运行它时,输出是 408 行而不是 418 行。当我在当前 python 进程中重新运行它时,它会输出预期的 418 行。我发布了包含所有相关位的代码的编辑部分。有任何想法吗?
import csv
import numpy as np
csvFile = open("/train.csv","ra")
csvFile = csv.reader(csvFile)
header = csvFile.next()
testFile = open("/test.csv","ra")
testFile = csv.reader(testFile)
testHeader = testFile.next()
writeFile = open("/gendermodelDebug.csv", "wb")
writeFile = csv.writer(writeFile)
count = 0
for row in testFile:
if row[3] == 'male':
do something to row
writeFile.writerow(row)
count += 1
elif row[3] == 'female':
do something to row
writeFile.writerow(row)
count += 1
else:
raise ValueError("Did not find a male or female in %s" % row)