# How would I save a dictionary of dataframes that I can import to another file?

**URL:** https://discourse.julialang.org/t/how-would-i-save-a-dictionary-of-dataframes-that-i-can-import-to-another-file/36042
**Category:** General Usage
**Created:** [March 16, 2020, 1:14pm UTC](https://discourse.julialang.org/t/how-would-i-save-a-dictionary-of-dataframes-that-i-can-import-to-another-file/36042 "2020-03-16T13:14:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Julia1](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Julia1](https://discourse.julialang.org/u/Julia1)
#### Post date: [March 16, 2020, 1:14pm UTC](https://discourse.julialang.org/t/how-would-i-save-a-dictionary-of-dataframes-that-i-can-import-to-another-file/36042/1 "2020-03-16T13:14:53Z")

</div>

Hi how are you,

I have a dictionary where all the values are dataframes. I want to be able to save/export this dictionary of dataframes and import it in another file.

Whats the best way to do this?

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [March 16, 2020, 1:25pm UTC](https://discourse.julialang.org/t/how-would-i-save-a-dictionary-of-dataframes-that-i-can-import-to-another-file/36042/2 "2020-03-16T13:25:47Z")

</div>

realistically, save each data-frame as a .csv in a subfolder and then write a function that reads all the .csv files into separate data frames and creates a dict from that.

---

<div class="post-metadata">

### Author: ![Pbellive](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbellive/32/3604_2.png) [@Pbellive](https://discourse.julialang.org/u/Pbellive)
#### Post date: [March 16, 2020, 3:54pm UTC](https://discourse.julialang.org/t/how-would-i-save-a-dictionary-of-dataframes-that-i-can-import-to-another-file/36042/3 "2020-03-16T15:54:03Z")

</div>

Assuming you only need to access these data from another julia session and not from another platform, you could just save the whole dictionary in a jld2 file. Or is use of JLD2 not recommended with DataFrames? If so, why is that?

---

<div class="post-metadata">

### Author: ![Manu\_Francis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manu_francis/32/10010_2.png) [@Manu\_Francis](https://discourse.julialang.org/u/Manu_Francis)
#### Post date: [March 16, 2020, 11:37pm UTC](https://discourse.julialang.org/t/how-would-i-save-a-dictionary-of-dataframes-that-i-can-import-to-another-file/36042/4 "2020-03-16T23:37:31Z")

</div>

@Julia1: You can use JLD2 package([GitHub - JuliaIO/JLD2.jl: HDF5-compatible file format in pure Julia](https://github.com/JuliaIO/JLD2.jl)) to save and load files by using command in REPL  
`]add JLD2`  
Then you can use it by using

```julia
using JLD2, FileIO
X = Dict(1 => [0,0,0],
              2 => [1,0,0],
              3 => [5,3,0],
              4 => [6,5,1])
@save "example.jld2" X

```

and you can load saved variables by using following command:  
` @load "example.jld2"`

---

<div class="post-metadata">

### Author: ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)
#### Post date: [March 17, 2020, 2:05am UTC](https://discourse.julialang.org/t/how-would-i-save-a-dictionary-of-dataframes-that-i-can-import-to-another-file/36042/5 "2020-03-17T02:05:06Z")

</div>

In my, admittedly not very extensive, experience: JLD2 seems to work reliably when the files are not too large and/or when the files only contain “built-in” Julia objects.

I just had a case where I saved a `Dict` where each entry was a simple `Dict{Symbol, Matrix{Float64}`. I have not found a way of reliably reading those files from disk when the “outer” `Dict` has a couple of thousand entries. A number of different errors were thrown.

Small files containing user defined objects have so far worked reliably.

Again, others likely have more extensive experience. Perhaps my experience is an outlier. I would love to know about tricks that make loading reliable. It would save me a lot of headaches.

For now I switched to saving everything that I cannot lose with `JSON3.jl`.
