Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Introduction

CSV (Comma Separated Values) may be a simple file format accustomed to


store tabular data, like a spreadsheet or database. CSV file stores tabular data
(numbers and text) in plain text. Each line of the file could be a data record. Each
record consists of 1 or more fields, separated by commas, the utilization of the
comma as a field separator is that the source of the name for this file format.

Basic Operations with CSV Files

In Basic operations, we are going to understand the subsequent three things:

1. How to work with CSV files


2. How to open a CSV file
3. How to Save a CSV file

Working with CSV Files

Working with CSV files isn’t that tedious task but it’s pretty straightforward.
However, counting on your workflow, there can become caveats that you
simply might want to observe out for.

Opening a CSV File

If you’ve got a CSV file, you’ll open it in Excel without much trouble. Just open
Excel, open and find the CSV file to figure with (or right-click on the CSV file and
choose Open in Excel). After you open the file, you’ll notice that the info is
simply plain text put into different cells.

Saving a CSV File

If you wish to save lots of your current workbook into a CSV file, you have got to
use the subsequent commands:

File -> Save As… and choose CSV file.

Importing Pandas
Firstly, we import the necessary dependencies such as Pandas Library of Python.

import pandas as pd

So, the dependency is imported, now we can load and read the dataset easily.

read-csv function
 It is an important pandas function to read CSV files and do operations on
them.
 This function helps us to load the file either from your local machine or
from any URL.

Opening a local CSV file


If the file is present in the same location as in our Python File, then give the file
name only to load that file, otherwise, you have to give the relative path to it.

df = pd.read_csv('aug_train.csv')
print(df)

Program-1.

Write a program to read from a CSV file


Employee.CSV and create a DataFrame from
it
Output

Program -2
Write a program to read from a CSV file Employee.Csv create a
dataframe from 8 but data frame should not use files column
header rather should use own column numbers as 0,1,2 and so on.
Output

Program -3.
Program to read from a CSV file employee. Csv and create a
DataFrame from it. Use Empno column as index labels
Output-

Program-4.
Program to read from a csv file employee. Csv and create a
DataFrame from it but data frame should not use files column
header rather should use on column reading as EmplD,
EmpName,Designation and salary.Also print the maximum salary
given to an employee
Output-

Program-5.
Write a program to read the records from file employee.Csv in
DataFrame and print the last two rows stored in the CSV file
Output:-

You might also like