After doing Machine Learning in Python 3.5.x How to save predicted output to CSV files using PANDAS library or CSV library??
Asked
Active
Viewed 4,155 times
1 Answers
2
If you have a pandas DataFrame df
, it can be saved to a CSV file using to_csv frunction.
df.to_csv("some_file.csv")
-
Im having a variable which i got after doing ML "y-pred". I would like to save that – Adarsh C Feb 08 '18 at 01:33
-
What is the format y-pred? If it is in a pandas DataFrame, `df` and you just want to save a column called 'y-pred' you would call `df['y-pred'].to_csv(path)`, where path would be `'/some_folder/some_file_name.csv'` – Blazina Feb 08 '18 at 08:10
-
It is in type
– Adarsh C Feb 08 '18 at 12:55 -
You can save numpy arrays using: `numpy.savetxt("some_name.csv", some_numpy_array, delimiter=",")` : see https://stackoverflow.com/questions/6081008/dump-a-numpy-array-into-a-csv-file – Blazina Feb 08 '18 at 15:01