Search code examples
pythonpandascsvheaderheader-row

When loading CSV data with pandas, the first line is mistaken for the title


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)).


Solution

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