SO,
I have a CSV file with a varying number of columns which I think means that the traditional means of making headers as I have attempted below won't work...
The reason I want some headers is because it gets incredibly difficult to use csv files with 100+ columns and do things like rPol = math.exp((((-1.2359386)+float(row[48])*(row[33])+row[29]+row[13]+row[97]/row[50])))
Trying to remember the identity of each row is a nussance, and it would be much easier if I could do something like:
rPol = math.exp((((-1.2359386)+float(depolscore)*(master_num)+ripen+offset_score+full/epilic)))
import csv
reader = csv.reader(open("test.csv"), delimiter=",")
headers = {"data", "title", "here", "testing", "stackoverflow"}
csv.DictWriter(reader, headers)
reader.writeheader()
for row in reader:
print testing
How would I go about giving specific columns a header without doing something like this:
for row in reader:
# put the columns into variables...
data = row[0]
title = row[1]
here = row[2]
testing = row[3]
stackoverflow = row[4]
# Do math
score = data * here / stackoverflow
# Print for user sake
print score
# Change the testing value
testing = testing + (score - title)
# Put values back into the reader object?
row[0] = data
row[1] = title
row[2] = here
row[3] = testing
row[4] = stackoverflow
Any ideas?