CSV file write problem

Here is my code: test_file = open(‘C:/Users/ABC/Downloads/test.csv’, ‘rt’) test_file_object = csv.reader(test_file) header = test_file_object.__next__() predictions_file = open(“genderclassmodel.csv”, “wt”,newline=”) p = csv.writer(predictions_file) p.writerow([“PassengerId”, “Survived”]) for row in test_file_object: # We are going to l # in the test set for j in range(number_of_price_brackets): # For each passenger we # loop thro each price bin try: # Some passengers have no # Fare data so try to make row[8] = float(row[8]) # a float except: # If fails: no data, so bin_fare = 3 – float(row[1]) # bin the fare according Pclass break # Break from the loop if row[8] > fare_ceiling: # If there is data see if # it is greater than fare # ceiling we set earlier bin_fare = number_of_price_brackets-1 # If so set to highest bin break #…


Link to Full Article: CSV file write problem

Pin It on Pinterest

Share This

Join Our Newsletter

Sign up to our mailing list to receive the latest news and updates about homeAI.info and the Informed.AI Network of AI related websites which includes Events.AI, Neurons.AI, Awards.AI, and Vocation.AI

You have Successfully Subscribed!