How to read Pandas csv file with no header?

0 votes
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 3, 2019 in Python by Raj
7,605 views

2 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 3, 2019 by Shri
file = pd.read_csv('Diabetes.csv', header=None) 
We need to keep header as None instead of 1
0 votes

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 by Shahabuddin
• 140 points

Related Questions In Python

0 votes
1 answer

How to create blank csv file in pandas?

Try this code: open("User data.csv", 'w') Where User data.csv ...READ MORE

answered Apr 5, 2019 in Python by Will
1,503 views
0 votes
2 answers

How to check if a csv file is empty in pandas?

Try this: df = pd.DataFrame(columns=['Name', 'ID', 'Department']) if df.empty ...READ MORE

answered Jul 1, 2019 in Python by Bob
2,022 views
0 votes
1 answer
+1 vote
4 answers

How to write nested dictionaries to a CSV file

Using DictWriter there is no need in ...READ MORE

answered Oct 18, 2018 in Python by Richard William
9,432 views
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 777 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer

How to print just one column in pandas?

You can use the header to print ...READ MORE

answered Apr 3, 2019 in Python by TIna
227 views
+1 vote
2 answers

How to install tkinter in pycharm?

Ya, this is a problem with installing ...READ MORE

answered Apr 3, 2019 in Python by Jishan
15,814 views