I have a bunch of CSV files that Im trying to concatenate into one single csv file . The CSV files are separated by a single space and look like this:
'initial', 'pos', 'orientation', 'ratio'
'chr', '106681', '+', '0.06'
'chr', '106681', '+', '0.88'
'chr', '106681', '+', '0.01'
'chr', '106681', '+', '0.02'
As you can see, all the values are the same except for the ratio
. The concatenated file I am creating will look like this:
'filename','initial', 'pos', 'orientation', 'ratio1','ratio2','ratio3'
'jon' , 'chr', '106681', '+', '0.06' , '0.88' ,'0.01'
So basically, ill be iterating through each file, storing only one value of the initial
, pos
, orientation
but all the values of the ratio
and updating the table in the concatenated file. This is proving much more confusing than i though it would be. I have the following piece of code to read the csv files:
concatenated_file = open('josh.csv', "rb")
reader = csv.reader(concatenated_file)
for row in reader:
print row
which gives:
['chrom', 'pos', 'strand', 'meth_ratio']
['chr2', '106681786', '+', '0.06']
['chr2', '106681796', '+', '0.88']
['chr2', '106681830', '+', '0.01']
['chr2', '106681842', '+', '0.02']
It would be really helpful if some one can show me how to store only one value of the initial
, pos
, orientation
(because they remain same) but all the values of the ratio