Writing CSV

333 views
Skip to first unread message

digxx

unread,
Nov 17, 2015, 4:29:42 PM11/17/15
to julia-users
with
writedlm("C:\\Users\\Diger\\Documents\\Julia\\x_values.csv",zip(x_s[1,1:end],x[1:end],epsilon[1,1:end,1],omega[300,1:end,1]),',')
I wanted to write a csv file comma separated...
Now in the manual it says that everything is saved as string, though the last column (omega) is saved as double which is actually what i wanted.
How can I get the others to be saved as double as well?

Milan Bouchet-Valat

unread,
Nov 18, 2015, 4:43:00 AM11/18/15
to julia...@googlegroups.com
Could you provide a reproducible example, with a few vectors holding
dummy data (i.e. x_s, x, epsilon and omega)?


Regards

digxx

unread,
Nov 21, 2015, 2:05:57 PM11/21/15
to julia-users
Though this is not a big issue since I can convert the strings to double as I want IDL still tells me the following

IDL>corr=read_csv(dir+'writecsv_test.csv')
IDL> help,corr
** Structure <a683f30>, 4 tags, length=1176, data length=1176, refs=1:
   FIELD1          DOUBLE    Array[21]
   FIELD2          STRING    Array[21]
   FIELD3          STRING    Array[21]
   FIELD4          STRING    Array[21]

with the file generated by:
a=collect(1:10);
b=collect(0:0.1:2);
c=zeros(1,1,10);
c[1,1,:]=a;
xx=b;
xx_s=broadcast(+,a,b');
eps=broadcast(-,a,b');
omga=broadcast(*,xx_s,c);
writedlm(dirname(@__FILE__)*"\\writecsv_test.csv",zip(xx_s[1,1:end],xx[1:end],eps[1,1:end],omega[10,1:end,1]),',')

Milan Bouchet-Valat

unread,
Nov 22, 2015, 7:02:15 AM11/22/15
to julia...@googlegroups.com
Le samedi 21 novembre 2015 à 11:05 -0800, digxx a écrit :
> Though this is not a big issue since I can convert the strings to
> double as I want IDL still tells me the following
OK, so this is actually an issue in the interaction between Julia
-produced CSV and how IDL interprets it. Note that CSV files do not
have any notion of variable types, this is all a matter of parsing
conventions.

It seems that IDL doesn't like the fact that Julia writes floating
point values that happen to be integers without printing the decimal
point. Could you try editing the CSV file by hand and add '.' at the
end of all numbers that don't have it? If IDL reads it correctly as
doubles, we might want to do this by default.


(BTW, you never need to write 1:end: xx_s[1,1:end] can be written
xx_s[1, :], and x[1:end] is simply x.)


Regards

digxx

unread,
Dec 5, 2015, 8:02:36 AM12/5/15
to julia-users
Hey, I had a look in it:
Its not the '.' on its on but also the fact that in front of the '.' IDL expects a '0' in case the number is smaller than 1
Then everything is read as double.

Milan Bouchet-Valat

unread,
Dec 5, 2015, 5:20:13 PM12/5/15
to julia...@googlegroups.com
Thanks. Can you check/confirm whether writing '1.0' as '1' in a column
containing other non-integer floats is supported by IDL? In other
words, is the problem only with writing '0.5' as '.5'?


Regards

digxx

unread,
Dec 5, 2015, 6:24:03 PM12/5/15
to julia-users
Yep, writing 1.0 as integer '1' still gives a double array when read by IDL

Milan Bouchet-Valat

unread,
Dec 6, 2015, 5:10:55 AM12/6/15
to julia...@googlegroups.com
Le samedi 05 décembre 2015 à 15:24 -0800, digxx a écrit :
> Yep, writing 1.0 as integer '1' still gives a double array when read
> by IDL
Thanks. I've filed an issue with a fix proposal:
https://github.com/JuliaLang/julia/issues/14291
Reply all
Reply to author
Forward
0 new messages