Is there a way to use strings as separators in writetable () - Julia

When using writeetable () to write a data frame to a file, I would like to be able to have the separator be a space and then a comma (ie "," as a separator). I know that writeetable () has the ability to have a single char as a delimiter argument. Is there a possible workaround to have a string as a separator?

Or can you just add a space after each individual data point in the data frame, and then output it as usual in a CSV file, so essentially with a delimiter "," in the file?

+4
source share
1 answer

You can do this with a function writedlmif you convert your DataFrame to an array:

using DataFrames
A = DataFrame(rand(3,3));
B = convert(Array, A);
writedlm("/path/to/file.txt", B,  ", ")

To include a header, you can use something like this:

f = open("/path/to/file.txt", "w")
writedlm(f, names(A)', ", ")
writedlm(f, B,  ", ")
close(f)

Note1: do not forget the transpose operation 'onnames(A)'

Note2: Rather, I believe that it writedlmwill have an option header_string. See here .

+2
source

All Articles