0

I have a large csv file with 100's of columns in it. Currently im able to read the csv file and its particular row. My file is inside a zipfile and here is the code i have so far.

import os, sys, csv, zipfile

zip_file = zipfile.ZipFile('some_zip_file.zip')
f = zip_file.open('some_csv_file.csv', 'r')

for row in csv.reader(f):
    print row[1]

f.close()

But is there a way to extract only the column names from the csv file? Im using python 2.7

2 Answers 2

3

next(csv.reader(f)) will return just the first row (which is presumably where the column names are.)

Sign up to request clarification or add additional context in comments.

Comments

1

Just get the first line of the file, by your code:

import os, sys, csv, zipfile

zip_file = zipfile.ZipFile('some_zip_file.zip')
f = zip_file.open('some_csv_file.csv', 'r')

for column in csv.reader(f).next():
    print column
    # collumn_name

Hope that helps.

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.