# Dataframe : Length of column

**URL:** <https://discourse.julialang.org/t/dataframe-length-of-column/19664>\
**Category:** General Usage\
**Created:** [January 15, 2019, 3:36pm UTC](https://discourse.julialang.org/t/dataframe-length-of-column/19664 "2019-01-15T15:36:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobLW](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roblw/32/6776_2.png) [@RobLW](https://discourse.julialang.org/u/RobLW)\
**Post date:** [January 15, 2019, 3:36pm UTC](https://discourse.julialang.org/t/dataframe-length-of-column/19664/1 "2019-01-15T15:36:33Z")

</div>

Hello,

If I have a DataFrame that for example is 91 rows 3 columns, and I would like to add a 4th column to it which measures the length of the data found in column 3. How can I apply this over each row please.

The following gives me 91 in each row, which isn’t what I’m looking for.

```julia
df[:colName] = length(df.Column3)

```

An example in python I would use the following below, which would measure the length of column3 on each row and input the number into column4.

```julia
df['Length'] = df.Column3.apply(len)

```

Many thanks.  
ps. I have been trying to google and forum search. But the only answers I’m finding I cannot understand how to make it work, something to do with map.

---

<div class="post-metadata">

**Author:** ![RobLW](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roblw/32/6776_2.png) [@RobLW](https://discourse.julialang.org/u/RobLW)\
**Post date:** [January 15, 2019, 3:49pm UTC](https://discourse.julialang.org/t/dataframe-length-of-column/19664/2 "2019-01-15T15:49:36Z")

</div>

Ah sorry. I just figured out the solution thanks to this great post

> [DataFrames.jl - Vectorized row-wise function application](https://discourse.julialang.org/t/dataframes-jl-vectorized-row-wise-function-application/14513)

I ended up creating a function as

```julia
f(a) = length(a)

```

Then calling it on the new column

```julia
df[:ColName] = f.(df.Column3)

```

Not sure if this is the best way. Would appreciate to know if there are other ways.  
Thanks

---

<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:** [January 17, 2019, 1:01pm UTC](https://discourse.julialang.org/t/dataframe-length-of-column/19664/3 "2019-01-17T13:01:10Z")

</div>

Why not broadcast `length` directly?

```julia
df[:col_3_length] = length.(df.col_3)

```

---

<div class="post-metadata">

**Author:** ![RobLW](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roblw/32/6776_2.png) [@RobLW](https://discourse.julialang.org/u/RobLW)\
**Post date:** [January 18, 2019, 9:30am UTC](https://discourse.julialang.org/t/dataframe-length-of-column/19664/4 "2019-01-18T09:30:25Z")

</div>

Thats great. I am not yet aware of this syntax in Julia (just learning it atm from a book).

Thank you.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 18, 2019, 10:12am UTC](https://discourse.julialang.org/t/dataframe-length-of-column/19664/5 "2019-01-18T10:12:06Z")

</div>

I would recommend working through the manual first, it is very nicely written.
