# Split Column in Dataframe

**URL:** https://discourse.julialang.org/t/split-column-in-dataframe/68036
**Category:** New to Julia
**Tags:** dataframes
**Created:** [September 11, 2021, 9:45pm UTC](https://discourse.julialang.org/t/split-column-in-dataframe/68036 "2021-09-11T21:45:43Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![dbjulia](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dbjulia](https://discourse.julialang.org/u/dbjulia)
#### Post date: [September 11, 2021, 9:45pm UTC](https://discourse.julialang.org/t/split-column-in-dataframe/68036/1 "2021-09-11T21:45:43Z")

</div>

I am trying to figure out how split a column of strings into a set number of columns. I have the example below. I want to split the column name from the titanic dataset into four columns. I know I can use this code to create one column called LastName: df.LastName = first.(split.(df.Name," ") and can do the same to get the last value just replace first with last. However, I cannot figure out a way to get the rest of the values. In the below code performing the split creates a substring vector I cannot figure out a way to indice or iterate through it to get the values I want to split them into several columns.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/f/6f5206b01b582d07a3aaabacea8362dcc560916c.png)

---

<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: [September 11, 2021, 10:10pm UTC](https://discourse.julialang.org/t/split-column-in-dataframe/68036/2 "2021-09-11T22:10:36Z")

</div>

Are they all the same length? If so you can do

```julia
transform(df, :Name => ByRow(split) => AsTable)

```

then rename them after

in DataFramesMeta this is

```julia
@rtransform df $AsTable = split(:Name)

```

EDIT: Even better

```julia
transform(df, :Name => ByRow(split) => [:first, :middle, :last])

```

or

```julia
@rtransform df $[:first, :middle, :last] = split(:Name)

```

---

<div class="post-metadata">

### Author: ![dbjulia](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dbjulia](https://discourse.julialang.org/u/dbjulia)
#### Post date: [September 12, 2021, 7:56pm UTC](https://discourse.julialang.org/t/split-column-in-dataframe/68036/3 "2021-09-12T19:56:49Z")

</div>

Thank you pdeffebach this was the fix. I wanted to mention something and ask a question. I see that you are one of the major contributors to this package for Julia and I must say this package is great, it functions a lot like R and the syntax and paradigm is quite easy to understand. I am new to programming and Julia and I am really liking the potential and current state of Julia is there a way for me to contribute for one to the DataFramesMeta package specifically and Julia as a whole, especially being I would say very novice programmer?

---

<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: [September 12, 2021, 11:17pm UTC](https://discourse.julialang.org/t/split-column-in-dataframe/68036/4 "2021-09-12T23:17:25Z")

</div>

Those are very kind words!

I think the best thing would be filing issues when you have problems or have ideas for new features.

Additionally, if you have a tutorial in another language that you really like, porting it to DataFramesMeta and having it be part of the docs would be very cool.

---

<div class="post-metadata">

### Author: ![dbjulia](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@dbjulia](https://discourse.julialang.org/u/dbjulia)
#### Post date: [September 14, 2021, 2:40am UTC](https://discourse.julialang.org/t/split-column-in-dataframe/68036/5 "2021-09-14T02:40:39Z")

</div>

Okay, I will do that, thanks for the help.

---

<div class="post-metadata">

### Author: ![merlin](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@merlin](https://discourse.julialang.org/u/merlin)
#### Post date: [February 4, 2022, 6:06am UTC](https://discourse.julialang.org/t/split-column-in-dataframe/68036/6 "2022-02-04T06:06:52Z")

</div>

> [@pdeffebach](#):
>
> `@rtransform df $[:first, :middle, :last] = split(:Name)`

I’m starting to realize the clarity and power of the DataFramesMeta package. Nice work!

I used this discussion to answer [an older stackoverflow question about this](https://stackoverflow.com/questions/57599906/how-to-separate-a-dataframe-column-in-two-given-a-delimiter)
