Wednesday, September 5, 2018

How to Export DataFrame in CSV File in Pandas | Pandas Tutorial 4 | Big Data Tutorial | Codeing School

This is Pandas Tutorial Part 4. pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.

How to Export DataFrame in CSV File in Pandas | Pandas Tutorial 4 | Big Data Tutorial | Codeing School
How to Export DataFrame in CSV File in Pandas | Pandas Tutorial 4


Today’s Topic: How to Export the DataFrame in a CSV File.


**First you need to import the Pandas Module.

import pandas as pd

**Then Create a DataFrame:

df=pd.DataFrame([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20]], columns=list('ABCD'))

df


Output:

A
B
C
D
0
1
2
3
4
1
5
6
7
8
2
9
10
11
12
3
13
14
15
16
4
17
18
19
20

How to Export DataFrame in CSV File in Pandas | Pandas Tutorial 4 | Big Data Tutorial | Codeing School
Create a DataFrame


Export the DataFrame As CSV Format:


df.to_csv(‘Export.csv’)


Logic: With the help of this df.to_csv(‘Export.csv’) syntax we can export the DataFrame as CSV format. Here, df is variable where the DataFrame stored. In ‘’ we write the CSV file name, where we want to export our DataFrame.

How to Export DataFrame in CSV File in Pandas | Pandas Tutorial 4 | Big Data Tutorial | Codeing School
Export DataFrame as CSV File


** To download the CSV file. Go Jupyter Notebook’s home, click on the CSV file, and click on Download. Otherwise, you can find the CSV file in your work folder too.

How to Export DataFrame in CSV File in Pandas | Pandas Tutorial 4 | Big Data Tutorial | Codeing School
Download DataFrame


And this is your CSV file,

How to Export DataFrame in CSV File in Pandas | Pandas Tutorial 4 | Big Data Tutorial | Codeing School
CSV File


** If you do not want the index, then you can write this syntax,


df.to_csv('Export.csv', index = False)

How to Export DataFrame in CSV File in Pandas | Pandas Tutorial 4 | Big Data Tutorial | Codeing School
Remove Index


There is no index like 0, 1, 2, 3, 4.

How to Export DataFrame in CSV File in Pandas | Pandas Tutorial 4 | Big Data Tutorial | Codeing School
CSV Without Index

Explore More About to_csv() Function, Read The Pandas Official Documentation. Click Here 

If you have, any quarry please comment below.


0 comments:

Post a Comment