I am currently using python, to read one CSV file and then just write the last column to a different CSV file.
My code for reading and writing is:
with open('source.csv', 'rb') as csvfile:
rdr = csv.reader(csvfile, delimiter=',', quotechar='|')
with open('result.csv', 'wb') as result:
wtr = csv.writer(result, delimiter=',', quotechar='|' )
for r in rdr:
wtr.writerow((r[2]))
The input looks like this:
#SYMBOL_NAME,TIMESTAMP,VALUE
,20140909230500.000000,0.000000
,20140909231000.000000,0.000000
,20140909231500.000000,0.000000
,20140909232000.000000,0.000000
,20140909232500.000000,0.000000
I am not interested in the timestamp and because of the software generating it, in this instance symbol name is an empty column.
I would expect my output to be like this:
VALUE
0.000000
0.000000
0.000000
0.000000
0.000000
However I am actually getting this:
V,A,L,U,E
0,.,0,0,0,0,0,0
0,.,0,0,0,0,0,0
0,.,0,0,0,0,0,0
0,.,0,0,0,0,0,0
0,.,0,0,0,0,0,0
Now I'm pretty sure that's because of delimiter=','
in the csv.writer
part. However when I try to set delimiter=''
to remove the commas I am told it must be at least one character string.
When I remove the delimiter
parameter all together then I get exactly the same output.