Trying to get code to output multiple columns in Python
Question: I am importing a data set and trying to output some text analysis. However, I
can only get it to output the last column of data. Where do I put the
csv.writer in order to get all the lines of code in?

    
    
    from __future__ import division
    import csv
    import re
    from string import punctuation
    
    faithwords = ['church', 'faith', 'faith']
    
    with open('dataset.csv', 'rb') as csvfile:
        data = csv.reader(csvfile, delimiter=",")
    
        for row in data:
    
            faithcounter = 0 
    
            row3 = row[3]
            row3 = row3.lower().replace('  ', ' ')
            row4 = row[4]
            row4 = row4.lower().replace('  ', ' ')
    
            for p in list(punctuation):
                row3 = row3.replace(p, '')
                row4 = row4.replace(p, '')
    
            essay1= re.split(' ', row3)
            essay2= re.split(' ', row4)
    
            essay1len = len(essay1)
            essay2len = len(essay2)
    
            num_of_rows = len(row)
    
            for word in essay1:
                if word in faithwords:
                    faithcounter = faithcounter + 1  
    
            for word in essay2:
                if word in faithwords:
                    faithcounter = faithcounter + 1            
    
            totallen = (essay2len + essay1len)
    
            row.append(essay1len)
            row.append(essay2len)
            row.append(totallen)
            row.append(faithcounter)        
            row.append(faithcounter / totallen)
    
            output = zip(row)
    
    writer = csv.writer(open('csvoutput.csv', 'wb'))
    writer.writerows(output)
    


Answer: Your problem is with this line:

    
    
    output=zip(row)
    

I'm not sure why you are doing `zip`, but I do know that your are overwriting
`output` on each iteration.

I recommend that you create your csv writer before your loop. Then, as the
last statement in your loop, do:

    
    
    writer.writerow(row)
    

