I have a csv file that look like this:
+-----+-----+-----+-----+-----+-----+-----+-----+ | AAA | bbb | ccc | DDD | eee | FFF | GGG | hhh | +-----+-----+-----+-----+---
import csv
DESIRED_COLUMNS = ('AAA','DDD','FFF','GGG')
f = open("myfile.csv")
reader = csv.reader(f)
headers = None
results = []
for row in reader:
if not headers:
headers = []
for i, col in enumerate(row):
if col in DESIRED_COLUMNS:
# Store the index of the cols of interest
headers.append(i)
else:
results.append(tuple([row[i] for i in headers]))
print results