How to read pandas read csv no with header

+1 vote
I have a csv file that I am importing in my Python script using pandas. The csv file start with cell values and doesn’t contain headings. Pandas is considering the first row value as heading. How to read csv without heading?
Apr 4, 2019 in Python by Raj
243,176 views

5 answers to this question.

0 votes

You can set the header option to None to ignore header.

file = pd.read_csv('Diabetes.csv', header=1)
answered Apr 4, 2019 by Shri
file = pd.read_csv('Diabetes.csv', header=None) 
We need to keep header as None instead of 1
+1 vote

Use this logic, if header is present but you don't want to read.

Using only header option, will either make header as data or one of the data as header. So, better to use it with skiprows, this will create default header (1,2,3,4..) and remove the actual header of file.

dfE_NoH = pd.read_csv('example.csv',header = 1)     

42 Jason Miller 25,000 4
0 52 Molly Jacobson 94,000 24
1 36 Tina . 57 31
2 24 Jake Milner 62 .

dfE_NoH = pd.read_csv('example.csv',header = None)

0 1 2 3 4
0 age first_name last_name postTestScore preTestScore
1 42 Jason Miller 25,000 4
2 52 Molly Jacobson 94,000 24
3 36 Tina . 57 31

df = pd.read_csv('example.csv', skiprows = 1,header = None)   

0 1 2 3 4
0 42 Jason Miller 25,000 4
1 52 Molly Jacobson 94,000 24
2 36 Tina . 57 31
3 24 Jake Milner 62 .
answered Mar 14, 2020 by Shahabuddin
• 160 points