- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Writing a Pandas DataFrame to CSV file
To write a Pandas DataFrame to CSV file, we can take the following Steps −
Steps
Create a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.
Print the input DataFrame.
Use df.to_csv to save the values of the DataFrame to a CSV (comma-separated values) file.
Example
import pandas as pd df = pd.DataFrame( { "x": [5, 2, 1, 9], "y": [4, 1, 5, 10], "z": [4, 1, 5, 0] } ) print "Input DataFrame is:
", df df.to_csv("test.csv", sep='\t')
Output
Input DataFrame is: x y z 0 5 4 4 1 2 1 1 2 1 5 5 3 9 10 0
It will create a new file ("test.csv") and save the values of the DataFrame in it.
- Related Articles
- Python - How to write pandas dataframe to a CSV file
- Writing data from database to .csv file
- Writing a CSV file in Java using OpenCSV
- Reading and Writing CSV File using Python
- How to Merge multiple CSV Files into a single Pandas dataframe ?
- Python Pandas- Create multiple CSV files from existing CSV file
- How to read a Pandas CSV file with no header?
- How to Merge all CSV Files into a single dataframe – Python Pandas?
- Python - Read csv file with Pandas without header?
- Write a Python code to read JSON data from a file and convert it to dataframe, CSV files
- How to read a JSON file into a DataFrame using Python Pandas library?
- How to put a Pandas DataFrame into a JSON file and read it again?
- How to parse a CSV file using PHP
- Writing UTF8 data to a file using Java
- Writing a binary file in C++

Advertisements