0

How to prevent the following? When I load a file with pd.read_csv(), the first line gets unwantedly treated as a header (list of column names):

import pandas as pd
data = pd.read_csv('namefile',sep=' ')
print(data)

and only the second line onwards gets treated as the data (vector = np.array(data)).

smci
  • 32,567
  • 20
  • 113
  • 146
3sm1r
  • 520
  • 4
  • 19
  • 2
    https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#csv-text-files, – wwii Aug 29 '19 at 16:48
  • `pd.read_csv(..., header=None)` as the doc says. (See the doc for more complex or multiline headers) – smci Aug 29 '19 at 22:14
  • Duplicate of [Prevent pandas read_csv treating first row as header of column names](https://stackoverflow.com/questions/40769691/prevent-pandas-read-csv-treating-first-row-as-header-of-column-names) and tons of others – smci Aug 29 '19 at 22:32
  • 1
    See [here](https://stackoverflow.com/a/56231664/4909087) for a cheatsheet of useful `read_csv` arguments you should know about. – cs95 Aug 30 '19 at 01:05

1 Answers1

4

you can use the option of header to exclude columns data=pd.read_csv('namefile',sep=' ', header =None)

Akshay Sapra
  • 436
  • 5
  • 22