# Vcat list of dataframes in for loop

**URL:** <https://discourse.julialang.org/t/vcat-list-of-dataframes-in-for-loop/30188>\
**Category:** General Usage\
**Created:** [October 22, 2019, 8:30pm UTC](https://discourse.julialang.org/t/vcat-list-of-dataframes-in-for-loop/30188 "2019-10-22T20:30:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FredC](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredc/32/9857_2.png) [@FredC](https://discourse.julialang.org/u/FredC)\
**Post date:** [October 22, 2019, 8:30pm UTC](https://discourse.julialang.org/t/vcat-list-of-dataframes-in-for-loop/30188/1 "2019-10-22T20:30:17Z")

</div>

I’m attempting something like

```julia
out = DataFrame()
for f in readdir(“csvs”)
vcat(out,CSV.read(f))
end

```

out is empty at the end of the for loop even though everything seems to be working.

Context is that I’m trying to memory-efficiently load a very large dataset that has been chunked into multiple csv files.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [October 22, 2019, 8:37pm UTC](https://discourse.julialang.org/t/vcat-list-of-dataframes-in-for-loop/30188/2 "2019-10-22T20:37:43Z")

</div>

You probably need to assign the result of vcat like

```julia
out = vcat(out, CSV.read(f))

```

---

<div class="post-metadata">

**Author:** ![FredC](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredc/32/9857_2.png) [@FredC](https://discourse.julialang.org/u/FredC)\
**Post date:** [October 22, 2019, 8:41pm UTC](https://discourse.julialang.org/t/vcat-list-of-dataframes-in-for-loop/30188/3 "2019-10-22T20:41:57Z")

</div>

Thanks. That doesn’t work in a for loop but using a function to control scope that does the trick.

If there are better ways to handle large data I’d be interested. This is my fallback after JuliaDB loadndsparse totally failed.

---

<div class="post-metadata">

**Author:** ![FredC](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredc/32/9857_2.png) [@FredC](https://discourse.julialang.org/u/FredC)\
**Post date:** [October 22, 2019, 8:53pm UTC](https://discourse.julialang.org/t/vcat-list-of-dataframes-in-for-loop/30188/4 "2019-10-22T20:53:56Z")

</div>

This may be impractically slow, however… it seems to be getting slower and slower, and memory may be starting to bloat…

---

<div class="post-metadata">

**Author:** ![Daniel\_Berge](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Daniel\_Berge](https://discourse.julialang.org/u/Daniel_Berge)\
**Post date:** [October 22, 2019, 9:14pm UTC](https://discourse.julialang.org/t/vcat-list-of-dataframes-in-for-loop/30188/5 "2019-10-22T21:14:56Z")

</div>

This can be done with a `mapreduce`.

```julia
out = mapreduce(vcat, readdir(“csvs”)) do f
    CSV.read(f)
end

```
