Adding commas to strings in an array and rewriting to CSV in Python

423
March 02, 2017, at 05:51 AM

I am looking to read in values from a one column CSV, find and replace all ">" characters with commas, and then write out to a multi-column CSV.

The following works for reading in, replacing, and appending to a new array but the CSV writer is writing out individual letters as columns. Any idea how to write back out with the newly appended commas as new columns?

import sys
import csv
import time
map_array = []
map_array_1 = []
reader = csv.reader(open('input_file.csv', 'rU'))
for row in reader:
    map_array.append(row)
for i in map_array:
    for j in i:
        hold = j.replace(">",",")
        map_array_1.append(hold)
writer = csv.writer(open('output_file.csv','wb'),delimiter=',')
for row in map_array_1:
    writer.writerow(row)
READ ALSO
How can you execute python terminal command using a Windows Batch script?

How can you execute python terminal command using a Windows Batch script?

So using Windows batch scripting I know we can open the python interpreter as follows and execute a python script:

341
Cuda issue in TensorFlow 1.0 tutorial looks like TF can't find CUPTI/lib64?

Cuda issue in TensorFlow 1.0 tutorial looks like TF can't find CUPTI/lib64?

This question has nothing to do with the warnings SSE AVX etcI've included the output for completeness

451
Calculating conditional probabilities for values in a 70+GB file

Calculating conditional probabilities for values in a 70+GB file

I am working on calculating conditional probabilities for values that are stored in a csv file, which is 70+ GB in sizeA sample dataset would be as follows:

223
How can I modify a sublime text 3 document via the in-app python console?

How can I modify a sublime text 3 document via the in-app python console?

I want to apply some function to the text of a documentLike for example run a regexp replacement and then convert the resulting text to lowercase (or some more complicated example that cannot be easily done with the provided tools)

327