How to Read a CSV File Without Header in Python?
Hi Dev,
In this tutorial, you will learn how to read a CSV file without header in python. you can understand a concept of read CSV file skip header python. you'll learn read CSV file without header python. step by step explain python read CSV file no header. Let's get started with how to read CSV file without header in python.
In this example, we will take one demo.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.
Example :
main.py
from csv import reader
# skip first line from demo.csv
with open('demo.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
print(row)
Output:
['1', 'Hardik Savani', '[email protected]']
['2', 'Vimal Kashiyani', '[email protected]']
['3', 'Harshad Pathak', '[email protected]']
Header Was:
['ID', 'Name', 'Email']
- Get Last 2 Digits of Number in Python Tutorial Example
- How to Sum of First and Last Digit of Number in Python?
- How to Get First and Last Digit of Number in Python?
- Get the Last Digit of Number in Python Tutorial Example
- Get the First Digit of Number in Python Tutorial Example
- How to Remove All Decimals from Number in Python?
- How to Convert String to Float with 2 Decimal Places in Python?
- How to Format Number to 2 Decimal Places in Python?