Writing a list from a for loop into a csv
<p>I wrote a for loop that iterates through a CSV to get a list like this:</p>

<pre><code>[t1, s1]
[t2, s2]
[t3, s3]
</code></pre>

<p>and so 4 thousand times. 
Now I need to write these into a new CSV file, where they'd populate 2 fields and be separated by a comma. 
When I enter this, I only get the last list from the last loop, and with one character in a cell. </p>

<pre><code>def sentiment_analysis():
    fo = open("positive_words.txt", "r")
    positive_words = fo.readlines()
    fo.close()
    positive_words = map(lambda positive_words: positive_words.strip(), positive_words)
    fo = open("negative_words.txt", "r")
    negative_words = fo.readlines()
    fo.close()
    negative_words = map(lambda negative_words: negative_words.strip(), negative_words)
    fo = open("BAC.csv", "r")
    data = fo.readlines()
    fo.close()
    data = map(lambda data: data.strip(), data)
    x1 = 0 #number of bullish
    x2 = 0 #number of bearish
    x3 = 0 #number of unknown
    for info in data:
        data_specs = info.split(',')
        time_n_date = data_specs[0]
        sentiment = data_specs[2]
        '''Possibly precede with a nested for loop for data_specs???'''
        if sentiment == 'Bullish':
            '''fo.write(time + ',' + 'Bullish' + '\n')'''
        elif sentiment == 'Bearish':
            ''' fo.write(time + ',' + 'Bearish' + '\n')'''
        else:
            x3 += 1
            positive = 0
            negative = 0
            content_words = data_specs[1].split()
            for a in positive_words:
                for b in content_words:
                    if (a == b):
                        positive = positive + 1
            for c in negative_words:
                for d in content_words:
                    if (c == d):
                        negative = negative + 1
            if positive &gt; negative:
                '''fo.write(time + ',' + 'Bullish' + '\n')'''
                sentiment = 'Bullish'
            elif positive &lt; negative:
                sentiment = 'Bearish'
            else:
                sentiment = 'Neutral'
        bac2data = [time_n_date, sentiment]
        print bac2data
        fo = open("C:\Users\Siddhartha\Documents\INFS 772\Project\Answer\BAC2_answer.csv", "w")
        for x in bac2data:
            w = csv.writer(fo, delimiter = ',')
            w.writerows(x)
        fo.close()
</code></pre>

<p>My for loop isn't going through it all.</p>