How to open CSV file in Python
A CSV file (Comma Separated Values) is a type of plain text file that uses specific structuring to arrange tabular data.
In python, the
csv library implements classes to read and write tabular data in CSV format.
Open a CSV file means to read a CSV file. Reading from a CSV file is done using the
The CSV file is opened as a text file with Python’s built-in
open() function, which returns a file object. This is then passed to the
Suppose we have a csv file as shown below.
import csv with open('Student.csv','r') as file: reader = csv.reader(file) for row in reader: print(row)
['Name', 'Age', 'Rollno'] ['Raju', '21', '1'] ['Kate', '20', '2'] ['Mary', '20', '3']
Since we have opened this csv file in ‘r’ read mode, we won’t be able to make changes to the file. You can just open the csv file and read the contents of the file.
Please login to comment
View all comments