I have a csv file with the following columns:
id,name,age,sex
Followed by a lot of values for the above columns. I am trying to read the column names alone and
here is the code to print only the headers or columns of the csv file.
import csv HEADERS = next(csv.reader(open('filepath.csv'))) print (HEADERS)
Another method with pandas
import pandas as pd HEADERS = list(pd.read_csv('filepath.csv').head(0)) print (HEADERS)