In this article, we are going to see different methods to save an NumPy array into a CSV file. CSV file format is the easiest and useful format for storing data
There are different methods by which we can save the NumPy array into a CSV file
Method 1: Using Dataframe.to_csv().
This method is used to write a Dataframe into a CSV file.
Example: Converting the array into pandas Dataframe and then saving it to CSV format.
[[ 1 2 3 4 5] [ 6 7 8 9 10]]
Method 2: Using numpy_array.tofile().
This method is used to write an array into the file.
Example: Create an array then save into a CSV file.
[ 1 2 3 4 5 6 7 8 9 10]
Method 3: Using numpy.savetext().
This method is used to save an array to a text file.
Example: Create an array then save as a CSV file.
- Create a GUI to convert CSV file into excel file using Python
- How to Convert an image to NumPy array and saveit to CSV file using Python?
- Convert HTML table into CSV file in python
- Python program to read CSV without CSV module
- Convert Text File to CSV using Python Pandas
- Different ways to import csv file in Pandas
- Saving Text, JSON, and CSV to a File in Python
- How to save a Python Dictionary to a CSV File?
- How to read a CSV file to a Dataframe with custom delimiter in Pandas?
- How to skip rows while reading csv file using Pandas?
- How to export Pandas DataFrame to a CSV file?
- Pandas - DataFrame to CSV file using tab separator
- Export Pandas dataframe to a CSV file
- Replacing column value of a CSV file in Python
- Load CSV data into List and Dictionary using Python
- Convert CSV to Excel using Pandas in Python
- Convert JSON to CSV in Python
- Convert CSV to HTML Table in Python
- Convert CSV to JSON using Python
- Convert Excel to CSV in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.