-1

After doing Machine Learning in Python 3.5.x How to save predicted output to CSV files using PANDAS library or CSV library??

Adarsh C
  • 11
  • 1
  • 2

1 Answers1

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")
shanmuga
  • 3,667
  • 2
  • 16
  • 33
Blazina
  • 798
  • 7
  • 11
  • 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