-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Description
Create a function that saves a table as CSV, possibly adding the prefixes row.
Taken from TulipaClustering:
"""
write_csv_with_prefixes(file_path, df; prefixes)
Writes the dataframe `df` into a csv file at `file_path`. If `prefixes` are
provided, they are written above the column names. For example, these prefixes
can contain metadata describing the columns.
"""
function write_csv_with_prefixes(file_path, df; prefixes = nothing, csvargs...)
if isnothing(prefixes) || length(prefixes) == 0
# If there are no prefixes, just write the data frame into the file
CSV.write(file_path, df; strict = true, csvargs...)
else
# Convert the prefixes to a one-row table for `CSV.write` to use
prefixes = reshape(prefixes, (1, length(prefixes))) |> Tables.table
# First we write the prefixes, then we append the data drom the dataframe
CSV.write(file_path, prefixes; header = false, strict = true, csvargs...)
CSV.write(file_path, df; header = true, append = true, strict = true, csvargs...)
end
return nothing
endMotivation
No response
Target audience
No response
Can you help
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels