# "Elongate" data frame based on column that contains arrays

**URL:** <https://discourse.julialang.org/t/elongate-data-frame-based-on-column-that-contains-arrays/74657>\
**Category:** New to Julia\
**Tags:** dataframes\
**Created:** [January 15, 2022, 9:26am UTC](https://discourse.julialang.org/t/elongate-data-frame-based-on-column-that-contains-arrays/74657 "2022-01-15T09:26:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![candidaorelmex](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@candidaorelmex](https://discourse.julialang.org/u/candidaorelmex)\
**Post date:** [January 15, 2022, 9:26am UTC](https://discourse.julialang.org/t/elongate-data-frame-based-on-column-that-contains-arrays/74657/1 "2022-01-15T09:26:26Z")

</div>

Hi everyone,

Im looking for a function that surely exists, but I just cant find it.  
I want to take a data frame, and create additional rows based on one of its columns which has arrays as entries. The idea is to split up the arrays of said column.

Example:

```julia
df = DataFrame(a = [1, 2, 3, [4, 4], 5], b = ["a", "b", "c", "e", "f"], c = [[22, 22], [33, 33], 44, 55, [66, 66, 66]])

function(df, :c)

```

should output

```julia
df = DataFrame(a = [1, 1, 2, 2, 3, [4, 4], 5, 5, 5], b = ["a", "a", "b", "b", "c", "e", "f", , "f", , "f"], c = [22, 22, 33, 33, 44, 55, 66, 66, 66])

```

I specified in the function I should elongate the df by `:c`, so the `[4, 4]` array in `:a` should remain untouched and, in case it’d be in row 1, should also get duplicated (which wouldn’t be the case here.

Is anyone aware of something like that?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 15, 2022, 11:06am UTC](https://discourse.julialang.org/t/elongate-data-frame-based-on-column-that-contains-arrays/74657/2 "2022-01-15T11:06:39Z")

</div>

Try flattening it:

```julia
flatten(df, :c)

```

---

<div class="post-metadata">

**Author:** ![candidaorelmex](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@candidaorelmex](https://discourse.julialang.org/u/candidaorelmex)\
**Post date:** [January 16, 2022, 7:14am UTC](https://discourse.julialang.org/t/elongate-data-frame-based-on-column-that-contains-arrays/74657/3 "2022-01-16T07:14:17Z")

</div>

Exactly what I was looking for, thank you!
