How to merge .csv files to do a matrix
Question: I have two different .csv files (a and b), containing several array organized
like this :

File a :

    
    
    [a, b, c, d]
    
    [e, f, g, h]
    
    [i, j, k, l]
    

File b :

    
    
    [o, p, q, r]
    
    [s, t, u, v]
    
    [w, x, y, z]
    

I want to merge these to files to get only on file (c), that would look like :

    
    
    [a, b, c, d, o, p, q, r]
    
    [e, f, g, h, s, t, u, v]
    
    [i, j, k, l, w, x, y, z]
    

Any ideas how I could do this? I'm running Python 2.7 (matplotlib,
openelectrophy).


Answer: With python's csv reader and writer,  
reading from the files `a.csv` and `b.csv`, writing to `c.csv`:

    
    
    # -*- coding: utf-8 -*-
    
    import csv
    
    with open('a.csv', 'r') as file_a:
        with open('b.csv', 'r') as file_b:
            with open('c.csv', 'w') as file_c:
                reader_a = csv.reader(file_a, delimiter=',')
                reader_b = csv.reader(file_b, delimiter=',')
                writer_c = csv.writer(file_c)
    
                for cols_a in reader_a:
                    cols_b = reader_b.next()
                    writer_c.writerow(cols_a + cols_b)
    

Creates file `c.csv`:

    
    
    a, b, c, d,o, p, q, r
    e, f, g, h,s, t, u, v
    i, j, k, l,w, x, y, z
    

(I assume that those braces and extra linebreaks in your csv code are just
here on stackoverflow and not really part of your csv files? I also assume
that a.csv and b.csv have the same length in lines.)

