CSV - writing to columns

Hello.
I would like to use the library csv to create a csv file from HashMap<String, Vec<i64>>. Where String is the header name and Vec is vector with values in column.
I need a function write_col(). Do you have any ideas?

Example output data (csv):

Time1	Time2	Time3
 1	     2	     3
 4	     5 	     6
 7       -       -

The exported file be used to generate histograms by Python (matplotlib, plotly).

It's not possible to write CSV data by columns, because it's inherently organized in row major order and is a variable-width format.

You can obtain an iterator to every column and advance them in lockstep, then write the CSV by rows as always, using the items yielded by each iterator for creating the rows.

2 Likes

Have you considered a columnar format like Arrow, Polars, or Parquet? They allow columns to be nullable, so you should be able to do what you describe. And at least Arrow and Polars both have CSV output.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.