I have my 500000 numerical values txt file.Couple of lines
-938.549927
-938.542419
-938.534912
-938.523621
-938.523621
-938.512329
-938.512329
-938.523621
-938.519836
-938.523621
-938.519836
-938.508606
-938.508606
-938.508606
-938.519836
-938.531128
-938.538635
I want so save it as csv file.I have tried this
import csv
lines = [line.rstrip('\n') for line in open('d500.txt')]
myfile = open('n500.csv', 'wb')
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
wr.writerow(lines)
I got this
wc -l n500.csv
1 n500.csv
Just part of the file
358337 "," -938.362061 "," -938.369568 "," -938.369568 "," -938.369568 "," -938.380859 "," -938.377075 "," -938.380859 "," -938.373352 "," -938.347046 "," -938.343262 "," -938.339539 "," -938.324524 "," -938.313232 "," -938.328247 "," -938.320740 "," -938.320740 "," -938.328247 "," -938.324524 "," -938.324524 "," -938.316956
What I really want is something like this
-938.316956
-938.316956
-938.313232
If I try
wr.writerows(lines)
format is crazy
" "," ","-","9","3","8",".","3","1","3","2","3","2"," "," "," "," "
" "," ","-","9","3","8",".","3","2","8","2","4","7"," "," "," "," "
" "," ","-","9","3","8",".","3","2","0","7","4","0"," "," "," "," "
" "," ","-","9","3","8",".","3","2","0","7","4","0"," "," "," "," "
" "," ","-","9","3","8",".","3","2","8","2","4","7"," "," "," "," "
" "," ","-","9","3","8",".","3","2","4","5","2","4"," "," "," "," "
" "," ","-","9","3","8",".","3","2","4","5","2","4"," "," "," "," "
" "," ","-","9","3","8",".","3","1","6","9","5","6"," "," "," "," "
" "," ","-","9","3","8",".","3","1","3","2","3","2"," "," "," "," "
" "," ","-","9","3","8",".","3","1","3","2","3","2"," "," "," "," "
" "," ","-","9","3","8",".","3","0","9","4","4","8"," "," "," "," "
" "," ","-","9","3","8",".","3","1","6","9","5","6"," "," "," "," "
" "," ","-","9","3","8",".","3","1","6","9","5","6"," "," "," "," "
" "," ","-","9","3","8",".","3","1","3","2","3","2"," "," "," "," "
My new code version
import csv
lines = [[line.rstrip('\n')] for line in open('d500.txt')]
myfile = open('n500.csv', 'wb')
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
wr.writerows(lines)
Than I got
" -938.324524 "
" -938.313232 "
" -938.328247 "
" -938.320740 "
" -938.320740 "
" -938.328247 "
" -938.324524 "
" -938.324524 "
" -938.316956 "
" -938.313232 "
" -938.313232 "
" -938.309448 "
" -938.316956 "
" -938.316956 "
" -938.313232 "
How to get rid of quotation marks?
d500.txtlooks like.writerowdoes as the name says, it writes a row. So your list of values is interpreted as one row.writerowsinstead