Hi,
I would like to write a DataFrame to a csv-file in DOS-style (‘\r\n’).
Something like
CSV.write(csv_file, DataFrame, delim=‘;’)
writes the usual ‘\n’ to the end of the line, but I need ‘\r\n’ line endings and couldn’t find a parameter to do it. How can I do it ?
This works (although it can probably be improved in various ways).
The conversion to an Array{Any,2} might be superfluous.
using DataFrames
using DelimitedFiles
x=["a" 1;"b" 2.3;"maha" 22]
df=DataFrame(A=String.(x[:,1]),B=Float64.(x[:,2]))
arr=convert(Array{Any,2},df)
fi="C:\\temp\\file2.csv"
isfile(fi)&&rm(fi)
fiostream=open(fi,"a+")
rows,cols=size(arr)
sep=','
for i=1:rows
v=view(arr,i,:)
for j=1:cols
elm=string.(v[j])
write(fiostream,elm)
j<cols&&write(fiostream,sep)
end
write(fiostream,"\r\n")
end
close(fiostream)