import csv sumbmit_csv_path = "submit_have_valid_SGD.csv" with open(sumbmit_csv_path, "w") as f: csv_writer = csv.writer(f) header = ['id', 'value'] print(header) csv_writer.writerow(header) for i in range(240): row = ['id_' + str(i), y_test[i][0]] csv_writer.writerow(row) print(row) print("over")