# Adding new column to DataFrame with Query.jl

**URL:** <https://discourse.julialang.org/t/adding-new-column-to-dataframe-with-query-jl/10889>\
**Category:** General Usage\
**Tags:** query, dataframes\
**Created:** [May 14, 2018, 7:18pm UTC](https://discourse.julialang.org/t/adding-new-column-to-dataframe-with-query-jl/10889 "2018-05-14T19:18:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [May 14, 2018, 7:18pm UTC](https://discourse.julialang.org/t/adding-new-column-to-dataframe-with-query-jl/10889/1 "2018-05-14T19:18:44Z")

</div>

Is there a way to use Query to just add a new column? In the docs there’s this example:

```julia
using Query, DataFrames

df = DataFrame(name=["John", "Sally", "Kirk"], age=[23., 42., 59.], children=[3,5,2])

x = @from i in df begin
    @select {i.name, Age=i.age}
    @collect DataFrame
end

```

but I’d like to do something like:

```julia
x = @from i in df begin
    @select {i, age_in_days=i.age*365}
    @collect DataFrame
end

```

to be equivalent to

```julia
x = @from i in df begin
    @select {i.name, i.age, i.children, age_in_days=i.age*365}
    @collect DataFrame
end

```

But what I get is:

```julia
3×2 DataFrames.DataFrame
│ Row │ i │ new_age │
├─────┼────────────────────────────────────────────┼─────────┤
│ 1 │ (name = "John", age = 23.0, children = 3) │ 8395.0 │
│ 2 │ (name = "Sally", age = 42.0, children = 5) │ 15330.0 │
│ 3 │ (name = "Kirk", age = 59.0, children = 2) │ 21535.0 │

```

I’ve got a giant table, so `@select`ing every column individually would be tedious. I know I can also just make a new vector and add it, but I’m doing a bunch of other filtering operations at the same time, and it would be nice to do them all at once.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [May 14, 2018, 7:58pm UTC](https://discourse.julialang.org/t/adding-new-column-to-dataframe-with-query-jl/10889/2 "2018-05-14T19:58:03Z")

</div>

Not right now, unfortunately. I’ve got a complete design on how to do this figured out, but it will only work with the new named tuples in julia 0.7, so we’ll have to wait until that is ready. The syntax will be `{i..., age_in_days=i.age*365}` once I get around to implementing this.

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [May 14, 2018, 9:22pm UTC](https://discourse.julialang.org/t/adding-new-column-to-dataframe-with-query-jl/10889/3 "2018-05-14T21:22:43Z")

</div>

@davidanthoff Awesome - that’s exactly what I’d expect for syntax (I actually tried that before writing here). Understand that it’s not implemented yet - I’ll just do it in two steps for now.

Thanks!
