I am translating the following Kaggle code into Python3.4:
In the final lines when outputting a CSV file,
predictions_file = open("myfirstforest.csv", "wb")
open_file_object = csv.writer(predictions_file)
open_file_object.writerow(["PassengerId","Survived"])
open_file_object.writerows(zip(ids, output))
predictions_file.close()
print('Done.')
there's a Type Error
TypeError: 'str' does not support the buffer interface
which occurs at the line open_file_object.writerow(["PassengerId","Survived"])
.
I believe this is because Opening a file in binary mode to write csv data to doesn't work in Python 3. However, adding encoding='utf8'
in the open()
line doesn't work either.
What is the standard way to do this in Python3.4?
newline=""'
, which is why I wanted a clarification. I apologize for causing you such distress. – Pneumonectomy