Saving Unitful DataFrame to file

Imagine I have a DataFrame with some of the columns being Unitful. Is there a way to save such a DataFrame into a file while preserving the information about the units?

The only solution I can think about is to strip it off units and save it to a .csv file. Then, when I load the file, I will have to multiply the columns by units.

But may be there is a good established approach to this?

1 Like

Does it need to be human readable? If not , Serialization.serialize works out of the box for DataFrames + Unitful. Serialization · The Julia Language

1 Like

No, it does not have to be human readable, but I would like loading the file to be fast.

serialization is pretty good then

By the way, does saving to .jld2 works as well?

I remember trying various serialization solutions and found Serialization to work best in terms of speed and serializing custom structs. Plus its a standard lib, which is a plus

For reference, a 450MB serialized dataframe file takes 109 ms to deserialize using Serialization.

1 Like

Everyone wants this (for the repl and e.g. writing to csv):

There is a PR too:

1 Like