I would like to replace the first row of my csv file. The csv file is generated by a script that opens other csv files and reads some columns. It looks like
TimeStamp;Value;Value; ...
2014/08/04 21:00:53.575;0.168889;1.146; ...
2014/08/04 21:01:23.590;0.168889;1.138; ...
2014/08/04 21:01:53.595;0.17;1.154; ...
2014/08/04 21:02:23.585;0.168889;1.205; ...
I would like to replace the first row (Timestamp;Value;Value) with the names is saved in a list.
The output I want should be
TimeStampfromlist;Firstnamefromlist;Secondnamefromlist; ...
2014/08/04 21:00:53.575;0.168889;1.146; ...
2014/08/04 21:01:23.590;0.168889;1.138; ...
2014/08/04 21:01:53.595;0.17;1.154; ...
2014/08/04 21:02:23.585;0.168889;1.205; ...
How can I do that?
Trying to be more specific this is the code I use to generate my csv file
import csv
import glob
import os, sys
path = "C:/Users/ButoeruG/Desktop/pythonscripts/prova"
dirs = glob.glob('*.csv')
namelist = dirs
print dirs[0]
file1 = dirs[1]
print file1
for file in namelist:
namelist = file.partition("TrendLogExtended_")[2].partition("-Ext).csv")[0]
print namelist
primofile = csv.reader(open(file1, 'rb'), delimiter=";", quotechar='|')
output_rows = []
for row in primofile:
output_rows.append([row[2], row[15]])
for file in dirs:
data = csv.reader(open(file, 'rb'), delimiter=";", quotechar='|')
column = []
for idx,row in enumerate(data):
output_rows[idx].append(row[15])
with open("provaoutput.csv", 'wb') as f:
writer = csv.writer(f, delimiter=';')
for row in output_rows:
writer.writerow(row)
Now the point is that when I write the row[15] I just copy from a file a column that looks like:
Value;
1,956;
1;054;
1,456;
I would like to replace value with part of the file name that I saved in namelist.