4

I have a csv file with one row of data with no header. Below is my code for importing data into a dataframe:

df2 = pd.read_csv(path2, header=0)

When I do read_csv it returns the following:

Empty DataFrame
Columns: [0.940456, 0.077893, 0.840178, 0.668612, 0.923643, 0.641833, 0.845249, 0.361605, 0.453943, 0.695509, 0.825763, 0.503687, 0.617303, 0.276637, 0.636244, 0.075744]
Index: []

df2.info() returns the following:

Index: 0 entries
Data columns (total 16 columns):
0.940456    0 non-null object
...

How do I set the first row as row instead of columns?

2
  • Is it the same when using header=None? Commented Feb 6, 2019 at 14:43
  • rows, you mean index or data part? Commented Feb 6, 2019 at 14:44

1 Answer 1

6

It means first row is converted to columns names, need header=None for default columns names with data in first row of DataFrame:

df2 = pd.read_csv(path2, header=None)
Sign up to request clarification or add additional context in comments.

1 Comment

The default behavior for pd.read_csv() is header=0 which means that the first line will be considered as column names while header=None will not take the first row as columns as indicated in the documentation.

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.