Python: Read CSV file with selected column

Posted: May 19, 2016 in Python

Hi, here are the basic code to read from the CSV file with selected column only using Python.


import csv

def read_file_csv (read_file):
    # i just want to read column 2, 3 and 4 from the csv file
    columns = [int(2, 3, 4)]
    with open(read_file, 'rb') as csvfile_read:
          reader = csv.reader(csvfile_read, delimiter=',')
          resultsCompareTo = []
          for row in reader:
                for i incolumns:
   return resultsCompareTo;

data = read_file_csv('the_file.csv')
print data

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s