title: Python: Error saving output into csv file?
body: <p>I realized this error only when open with MS Excel but it is just fine when open using Notepad++. The values are not in corresponding columns when I open using Excel. I have this following code which help me to do multiplication only according to value 1 in binary.csv and outputting values excluding all the 0 values in binary.csv. Can anyone help me?</p>
  
  <p><strong>binary.csv</strong></p>
  
  <pre><code>0,1,0,0,1,0,1,0,0
  1,0,0,0,0,1,0,1,0
  0,0,1,0,1,0,1,0,0
  </code></pre>
  
  <p><strong>real.csv</strong></p>
  
  <pre><code>0.1,0.2,0.4,0.1,0.5,0.5,0.3,0.6,0.3
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre><code>import csv
  
  with open('real.csv', 'rb') as csvfile:
      for row in csv.reader(csvfile, delimiter=','):
          reals = row
  
  with open('binary.csv', 'rb') as csvfile:
      pwreader = csv.reader(csvfile, delimiter=',')
  
      with open('onehothot.csv','wb') as testfile:
          csv_writer=csv.writer(testfile)
          for row in pwreader:
              result = []
  
              for i,b in enumerate(row):
                  if b == '1' :
                      result.append(reals[i])
  
              c= ",".join(result)
              print(c)
              csv_writer.writerow([c])
  </code></pre>
  
  <p><strong>Output in csv file open using Notepad++</strong></p>
  
  <pre><code>0.2,0.5,0.3
  0.1,0.5,0.6
  0.4,0.5,0.3
  </code></pre>
  
  <p><strong>Desired output in csv file open using MS Excel (in 3 rows and 3 columns filled)</strong></p>
  
  <pre><code>0.2 0.5 0.3
  0.1 0.5 0.6
  0.4 0.5 0.3 
  </code></pre>
  
  <p>The actual CSV output file I open using MS Excel is in 3 rows and 1 column filled because '0.2 0.5 0.3' is treated as single entity. Therefore only 3 entities displayed in Excel.</p>