# \`explode\`-like function in DataFrames

**URL:** <https://discourse.julialang.org/t/explode-like-function-in-dataframes/114113>\
**Category:** Data\
**Tags:** dataframes\
**Created:** [May 10, 2024, 3:08pm UTC](https://discourse.julialang.org/t/explode-like-function-in-dataframes/114113 "2024-05-10T15:08:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 10, 2024, 3:08pm UTC](https://discourse.julialang.org/t/explode-like-function-in-dataframes/114113/1 "2024-05-10T15:08:20Z")

</div>

If I have a DataFrame in which one of the columns has `Vector`s of one of more elements, how do I make each value to be a different row with the rest of the data copied? Ex.:

```julia
A | B 
[1, 17, 9] | "abc"
[2, 5] | "def"

```

becomes

```julia
A | B 
1 | "abc"
17 | "abc"
9 | "abc"
2 | "def"
5 | "def"

```

Other languages/frameworks have this function by the name of [`explode`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.explode.html). Every time I need to do some work I end up needing this function and I never remember how I solved the problem the last time. It is a major annoyance.

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [May 10, 2024, 3:25pm UTC](https://discourse.julialang.org/t/explode-like-function-in-dataframes/114113/2 "2024-05-10T15:25:32Z")

</div>

This function should do what you’re looking for

```julia
flatten(df,:A)

```

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 10, 2024, 3:30pm UTC](https://discourse.julialang.org/t/explode-like-function-in-dataframes/114113/3 "2024-05-10T15:30:03Z")

</div>

Thanks! For some reason I am not able to associate the term `flatten` with this command in `DataFrames`, `explode` always come first to my mind.

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [May 10, 2024, 3:31pm UTC](https://discourse.julialang.org/t/explode-like-function-in-dataframes/114113/4 "2024-05-10T15:31:44Z")

</div>

there was some [discussion](https://github.com/JuliaData/DataFrames.jl/issues/2766) about it some time ago

> [@Henrique\_Becker](#):
>
> `explode` always come first to my mind

these days it seems like a more frequent verb
