Thursday, September 4, 2025
HomeLanguagesHow to read csv file with Pandas without header?

How to read csv file with Pandas without header?

Prerequisites: Pandas

A header of the CSV file is an array of values assigned to each of the columns. It acts as a row header for the data. This article discusses how we can read a csv file without header using pandas. To do this header attribute should be set to None while reading the file.

Syntax:

read_csv(“file name”, header=None)

Approach

  • Import module
  • Read file
  • Set header to None
  • Display data 

Let us first see how data is displayed with headers, to make difference crystal clear.

Data file used:

Example1: 

Python3




# importing python package
import pandas as pd
  
# read the contents of csv file
dataset = pd.read_csv("file.csv")
  
# display the modified result
display(dataset)


Output:

Now let us see the implementation without headers.

Example 2:

Python3




# importing python package
import pandas as pd
  
# read the contents of csv file
dataset = pd.read_csv("file.csv", header=None)
  
# display the modified result
display(dataset)


Output:

Example 3:

Python3




# importing python package
import pandas as pd
  
# read the content of csv file
dataset = pd.read_csv("sample1.csv", header=None)
  
# display modified csv file
display(dataset)


Output:

RELATED ARTICLES

Most Popular

Dominic
32260 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS