How to Read CSV File Without Header in Python?

Published On: 06/01/2023 | Category: Python

Hi Dev,

In this example, I will learn python to read csv without header example. We will look at the example of a python reading csv file without a header example.

In this article, i will take one example.csv file with ID, Name and Email fields. Then, we will use open(), next() and reader() functions to read csv file data without header columns fields.

So let's see bellow example:

from csv import reader
# skip first line from example.csv
with open('example.csv', 'r') as readObj:
    csvReader = reader(readObj)
    header = next(csvReader)
    # Check file as empty
    if header != None:
        # Iterate over each row after the header in the csv
        for row in csvReader:
            # row variable is a list that represents a row in csv
['1', 'Bhavesh Sonagra', '[email protected]']
['2', 'Nikhil Patel', '[email protected]']
['3', 'Piyush Kamani', '[email protected]']

Header was:
['ID', 'Name', 'Email']

It will help you....