# Saving julia dataframes efficiently (in terms of size on the disk)

**URL:** https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151
**Category:** General Usage
**Created:** [December 11, 2019, 2:30pm UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151 "2019-12-11T14:30:58Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)
#### Post date: [December 11, 2019, 2:30pm UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/1 "2019-12-11T14:30:58Z")

</div>

What is a good format to store Julia DataFrames efficiently (in terms of size on the disk)? I have a dataset that is about 2.1GB as a Feather file. It is almost 1.9GB in Stata .dta format. But if I open it in R and save it in the .rds format, the size decreases to 239MB. Is there something like RDS format for Julia? I tried JuliaDB, but it does nothing to decrease the size on the disk.

Any recommendations for how the data could be stored on the disk.

Thanks.

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [December 11, 2019, 3:03pm UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/2 "2019-12-11T15:03:53Z")

</div>

You could try compressing Feather or another format with [gzip](https://github.com/JuliaIO/GZip.jl) or another general compression algorithm.

Feather supports compression via [CategoricalArrays](https://github.com/JuliaData/CategoricalArrays.jl). If you set columns of your table to be `CategoricalArray`s they will be stored in the feather file in a similar format. Of course, you will only get significant compression from this if your table happens to have lots of repeated values.

---

<div class="post-metadata">

### Author: ![ASF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asf/32/10610_2.png) [@ASF](https://discourse.julialang.org/u/ASF)
#### Post date: [December 11, 2019, 4:45pm UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/3 "2019-12-11T16:45:34Z")

</div>

I like [FstFileFormat](https://github.com/xiaodaigh/FstFileFormat.jl)

---

<div class="post-metadata">

### Author: ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)
#### Post date: [December 11, 2019, 6:03pm UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/4 "2019-12-11T18:03:23Z")

</div>

Thanks. Will look into this. I suppose this only works if columns contain Categorical data. Is that right? In general, is R achieving the small size because of compression? Does it compress and decompress automatically?

---

<div class="post-metadata">

### Author: ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)
#### Post date: [December 11, 2019, 6:03pm UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/5 "2019-12-11T18:03:58Z")

</div>

@ASF Thanks. Will try this out. Did not know about this one.

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [December 11, 2019, 6:08pm UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/6 "2019-12-11T18:08:31Z")

</div>

You can make a `CategoricalArray` out of anything, but it’ll only benefit you if the number of distinct values is much smaller than the number of elements in the array and the values are larger than a few bytes. It’s usually only useful for strings.

From the sizes you are seeing it’s obvious that R’s `rds` format is somehow compressed (the feather format is very simple, so it’s very unlikely that it’s going to “inflate” much) but I have no idea how. In extreme cases you can achieve that much from the `CategoricalArray` encoding, but more likely they are using some generalized compression algorithm (there’s a chance it’s gzip, since that is the most commonly used compression algorithm).

---

<div class="post-metadata">

### Author: ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)
#### Post date: [December 12, 2019, 12:52am UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/7 "2019-12-12T00:52:46Z")

</div>

@ExpandingMan  
Thanks very much for the explanation.

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [December 12, 2019, 1:02am UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/8 "2019-12-12T01:02:52Z")

</div>

I developed just this thing [https://github.com/xiaodaigh/JDF.jl](https://github.com/xiaodaigh/JDF.jl)

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [December 12, 2019, 1:03am UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/9 "2019-12-12T01:03:53Z")

</div>

It’s actually an R native format so the saving will be slow. Better use my other package [https://github.com/xiaodaigh/JDF.jl](https://github.com/xiaodaigh/JDF.jl) if u r happy to stay in Julia ecosystem

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [December 12, 2019, 6:01am UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/11 "2019-12-12T06:01:35Z")

</div>

R’s fst uses lots of compression algorithms. Rds is also compressed by default.

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [December 12, 2019, 6:05am UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/12 "2019-12-12T06:05:32Z")

</div>

> [@curious](#):
>
> t is almost 1.9GB in Stata .dta format. But if I open it in R and save it in the .rds format, the size decreases to 239MB

RDS does compression by default. Please try out [JDF.jl](https://github.com/xiaodaigh/JDF.jl). Based on one benchmark that I did, it’s much smaller than Feather if you have lots of strings. See

![fannie-mae-filesize-Performance_2004Q3.txt](https://global.discourse-cdn.com/julialang/original/3X/3/5/35a5ec0db88a731a320f5c1bc83d6fb78c46a6a3.png)

---

<div class="post-metadata">

### Author: ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)
#### Post date: [December 12, 2019, 6:59am UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/13 "2019-12-12T06:59:53Z")

</div>

very interesting package. any plan of adding native julia support to reading and writing fst format data?

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [December 12, 2019, 7:07am UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/14 "2019-12-12T07:07:16Z")

</div>

I would but you need c++. Which I Dont know any.

---

<div class="post-metadata">

### Author: ![curious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curious/32/7629_2.png) [@curious](https://discourse.julialang.org/u/curious)
#### Post date: [January 19, 2020, 2:41am UTC](https://discourse.julialang.org/t/saving-julia-dataframes-efficiently-in-terms-of-size-on-the-disk/32151/15 "2020-01-19T02:41:46Z")

</div>

@xiaodai So sorry for not replying sooner. Thank you so much for these responses. I got busy with something else. But I look forward to trying this out.

Thanks again.
