Writing DataFrame with no quotemarks

Function writetable requires a quotemark character. Is there a direct way to write a DataFrame to CSV file without any quotemarks?

I had the same question a while ago and you can follow the discussion here:

https://github.com/JuliaStats/DataFrames.jl/issues/811#issuecomment-108913671

So to my knowledge this is not supported in DataFrames, but I never actually followed this up on CSV.jl

I’m adding this option to CSVFiles.jl right now. Once that PR is merged and a new version is tagged, this should work:

using FileIO, CSVFiles

df = ...
save("file.csv", df, quotechar=nothing)

Or you can use the pipe style

df |> save("file.csv", quotechar=nothing)

df can be any iterable table, i.e. not just a DataFrame.

I’ll have to write some documentation for the whole FileIO.jl integration that we have now for iterable tables (for example, the same pattern also works for feather files via FeatherFiles.jl) soon.

2 Likes

Wow, that was quick! Thanks a lot, David.

I’m a beginner Julia user, so this may not be a good idea, but what about making quotemark a parameter of nullable type instead of adding an extra quote_char parameter?

Nevermind. I just looked at nullable types and the notation would be too cumbersome for mainstream usage:
quotemark = Nullable{Char}('"')

I’m using a Nullable in the internal implementation, but using them for he user facing API is less nice because you would have to construct a Nullable whenever you want to just pass in a character. Essentially the user facing API is now using Union{Char,Void}, which should make for the easiest API. [Had this post composed before lunch and see that you figured this out yourself in the meantime!]

Not sure what you mean by quotemark, there is no parameter with that name anywhere.

BUT, I took another look at the names for the optional parameters, and I’m changing quote_char to quotechar, that makes it consistent with CSV.jl and TextParse.jl. I’v edited my post from above accordingly.

I just used it in my code. Here is the documentation snippet:

writetable(filename, df, [keyword options])
...
quotemark::Char – The character used to delimit string fields. Defaults to '"'.

There is also a bad example there:

writetable("output.dat", df, quotemark = '', separator = ',')

Oooops! I meant DataFrames.writetable and you meant save. My mistake.