Save as a CSV file

Asked 1 years ago, Updated 1 years ago, 111 views

Hi, everyone. I am a college student who started studying machine learning. I want to save the predicted result value as a CSV file. The prediction results are stored in a variable called 'prediction' in a numpy array.

I want to save this prediction result as a csv file, and I want to make it like the figure below so that one prediction result value fits in one row.

But I don't know how to code it. It may be an easy question, but it is too difficult for me who just started studying.crying Help me

jupyter

2022-09-21 21:28

1 Answers

Hi, everyone. Try googling a poor answer.

There may be some missing parts due to lack of Python proficiency. ㅠ<

Referred to the code in the https://stackoverflow.com/questions/3345336/save-results-to-csv-file-with-python link.

import csv

res = ["prediction", 30, 50, 20, 10, 40] csvfile = "output.csv"

with open(csvfile, "w") as output:
    writer = csv.writer(output, lineterminator='\n')
    for val in res:
        writer.writerow([val])

I think you can change it properly and use it.


2022-09-21 21:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.