0% found this document useful (0 votes)
3 views

CSV File

Uploaded by

RAZER GAMING
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CSV File

Uploaded by

RAZER GAMING
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

CSV File(Comma Separated Values)

CSV is a simple file format used to store tabular data in plain text.Each record consists of one
or more fields , separated by commas.

Advantages

1. Simple and compact format for data storage.


2. A common format for data interchange.
3. Almost all databases and spreadsheets support import/export to CSV format.
4. It can be opened in MS Excel, OpenOfficeCalc etc.

Creating CSV file

CSV is a text file , so it can be created or edited using any text editor.

All csv files follows standard format.

Each column is separated by delimiter(comma,space,tab or semicolon).

Default delimiter is comma.


Steps to create CSV file.

• Open excel
• Create a tabular data(student table/ Employee table )

• Save the file with proper name .csv


• To view this file in a notepad/ wordpad open the file.
• You can see that the each column is separated by comma and each new line is a
record.

Reading from a CSV file to DataFrame


The read_csv() in Pandas allows you to read your csv file .It loads the data in a Pandas
dataframe.

Output

Reading CSV file with Specific columns

If we want to read selective columns to be read in to a DataFrame, the option or attribute


USECOLS can be using along with read_csv() method.
Eg:-
Output

Reading CSV file with Selected Rows

output
Reading CSV file without header

Output

Reading CSV file without index

Output
Reading CSV file with new column names

Output

UPDATING /MODIFYING CONTENTS IN A CSV FILE


Output

Copying the contents of a original CSV file to another/duplicate csv file


Saving Datframe as CSV file

If you open the file in a spreadsheet (MSExcel)


In the above output , unnamed:0 column gets displayed automatically along with the index
value. To avoid this column, use index_col=0 with read_csv().

Copying fields in to a new file.

Some situations we need only selected fields of a file.(use same field names in both files—
case sensitive)
Output

You might also like