# Why this dataframes.jl example uses a semicolon at the beginning?

**URL:** <https://discourse.julialang.org/t/why-this-dataframes-jl-example-uses-a-semicolon-at-the-beginning/71223>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [November 9, 2021, 8:21pm UTC](https://discourse.julialang.org/t/why-this-dataframes-jl-example-uses-a-semicolon-at-the-beginning/71223 "2021-11-09T20:21:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [November 9, 2021, 8:21pm UTC](https://discourse.julialang.org/t/why-this-dataframes-jl-example-uses-a-semicolon-at-the-beginning/71223/1 "2021-11-09T20:21:55Z")

</div>

I was reading some examples (from [https://bkamins.github.io](https://bkamins.github.io)) about how to use DataFrames.jl to select, filter, combine… and I have a question.

```julia-auto
df = DataFrame(
  id = 1:4,
  name = ["Aaron Aardvark", "Belen Barboza", "Elżbieta Elbląg", "Felipe Fittipaldi"],
  age = [50, 45, 30, 25],
  eye = ["blue", "brown", "blue", "brown"],
  grade_1 = [95, 90, 95, 90],
  grade_2 = [75, 90, 75, 95],
  grade_3 = [85, 85, 80, 85]
  )

select(df, :name => ByRow(x -> (; ([:firsname, :lastname] .=> split(x))...)))

```

What I don’t understand is this part:

> (; ([:firsname, :lastname] .=\> split(x))…

Why are they using a semicolon **;** there?  
Why do they need to spat … the output?

There is another thread about the semicolon

> [@When and where should we use semicolon](https://discourse.julialang.org/t/when-and-where-should-we-use-semicolon/23597/1):
>
> Problem This might be a somehow uninteresting question. But when I read other people’s code snippets, I find that the use of semicolon does not follow certain patterns and seems to be a little random for me. I know semicolon is used to suppress output just like in MATLAB. When I write code in MATLAB, I generally add semicolons everywhere like writing C/C++/Java. When output is needed, I just use print function to get what I want. I am not sure whether this is still preferable in Julia. If it i…

But I think it’s not the same. In that thread they use it to suppress printing the output.

Maybe in my example it’s related with “positional arguments” for functions, but I don’t understand it here.

---

<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:** [November 9, 2021, 8:57pm UTC](https://discourse.julialang.org/t/why-this-dataframes-jl-example-uses-a-semicolon-at-the-beginning/71223/2 "2021-11-09T20:57:09Z")

</div>

It’s because the anonymous function creates a named tuple. You can construct a named tuple programatically in Julia with `Pair`s.

```julia
julia> (; ([:a, :b] .=> 5)...)
(a = 5, b = 5)

```

That’s a pretty opaque piece of code for sure.

---

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [November 10, 2021, 1:06am UTC](https://discourse.julialang.org/t/why-this-dataframes-jl-example-uses-a-semicolon-at-the-beginning/71223/3 "2021-11-10T01:06:32Z")

</div>

> [@Juan](#):
>
> (; ([:firsname, :lastname] .=\> split(x))…

Can I achieve the same result without creating a named tuple?

---

<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:** [November 10, 2021, 1:10am UTC](https://discourse.julialang.org/t/why-this-dataframes-jl-example-uses-a-semicolon-at-the-beginning/71223/4 "2021-11-10T01:10:38Z")

</div>

You could put them in separate commands, write things out more explicitely.

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [November 10, 2021, 7:39am UTC](https://discourse.julialang.org/t/why-this-dataframes-jl-example-uses-a-semicolon-at-the-beginning/71223/5 "2021-11-10T07:39:39Z")

</div>

If you find this syntax messy there’s another way to write it that is maybe clearer:

```julia
select(df, :name => ByRow(x -> NamedTuple([:firsname, :lastname] .=> split(x))))

```

---

<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:** [November 10, 2021, 8:47am UTC](https://discourse.julialang.org/t/why-this-dataframes-jl-example-uses-a-semicolon-at-the-beginning/71223/6 "2021-11-10T08:47:00Z")

</div>

There’s no requirement to use the `select`/`combine`/`transform` minilanguage for everything you do in DataFrames. I would probably just write this as:

```julia
x = split.(df.name);
df.first_name, df.last_name = first.(x), last.(x)

```

---

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [November 10, 2021, 6:09pm UTC](https://discourse.julialang.org/t/why-this-dataframes-jl-example-uses-a-semicolon-at-the-beginning/71223/7 "2021-11-10T18:09:33Z")

</div>

Why does my example need a splat

`select(df, :name => ByRow(x -> (; ([:firsname, :lastname] .=> split(x))...)))`

but yours doesn’t  
`select(df, :name => ByRow(x -> NamedTuple([:firsname, :lastname] .=> split(x))))`  
?  
if both create NamedTuple

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [November 10, 2021, 6:39pm UTC](https://discourse.julialang.org/t/why-this-dataframes-jl-example-uses-a-semicolon-at-the-beginning/71223/8 "2021-11-10T18:39:28Z")

</div>

It’s just two different things that work differently: `NamedTuple(itr)` is a function (constructor) that takes a single parameter: an iterator of pairs. It’s a single parameter so you must not use splat. Another way to construct a named tuple is the `(; ...)` syntax. This one takes a list of pairs, here each pair is a “parameter”. So to make a list of parameters from a single iterator you need the splat.
