Writing to CSV issue in Spyder

Posted by 0003 on Stack Overflow See other posts from Stack Overflow or by 0003
Published on 2013-10-19T03:52:03Z Indexed on 2013/10/19 3:53 UTC
Read the original article Hit count: 171

Filed under:
|
|

I am doing the Kaggle Titanic beginner contest. I generally work in Spyder IDE, but I came across a weird issue. The expected output is supposed to be 418 rows. When I run the script from terminal the output I get is 418 rows (as expected). When I run it in Spyder IDE the output is 408 rows not 418. When I re-run it in the current python process, it outputs the expected 418 rows. I posted a redacted portion of the code that has all of the relevant bits. Any ideas?

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)

© Stack Overflow or respective owner

Related posts about python

Related posts about csv