1

I am reading a txt file (data.txt) using pandas read_csv method. The file has 16 columns and 600 rows. However, after reading the csv into dataframe, I observed that first row in my data.txt file has been taken as the column headings in the dataframe. This reduces the size of my dataframe to 599 from 600 in my text file. How can I force pandas to not use first row as headers for Dataframe. I am using this code to read the file.

import pandas as pd
df = pd.read_csv("C:\<my_directory_path>\data.txt)
1
  • pd.read_csv("FILE", header=False) Commented Dec 11, 2015 at 0:08

2 Answers 2

1

Just add header=None:

import pandas as pd
df = pd.read_csv("C:\<my_directory_path>\data.txt",header=None)
Sign up to request clarification or add additional context in comments.

Comments

0

You can use the parameter header=None to read your data in with integers to index the columns, alternatively if you know what the names of your columns are, you can pass in something like names=['col1','col2','col3']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.