# Prefixing output columns which are returned as Dataframe

**URL:** <https://discourse.julialang.org/t/prefixing-output-columns-which-are-returned-as-dataframe/98098>\
**Category:** Data\
**Tags:** dataframes, dataframemacros\
**Created:** [April 29, 2023, 6:56pm UTC](https://discourse.julialang.org/t/prefixing-output-columns-which-are-returned-as-dataframe/98098 "2023-04-29T18:56:43Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 30, 2023, 9:36am UTC](https://discourse.julialang.org/t/prefixing-output-columns-which-are-returned-as-dataframe/98098/10 "2023-04-30T09:36:31Z")

</div>

> [@mreichMPI-BGC](#):
>
> But your solution does not allow the programmatic addition of the suffix.

Based on a [master’s solution here](https://discourse.julialang.org/t/construct-namedtuple-dynamically/15394/8), I have adapted the code to handle it:

```julia
using DataFrames

function calc(x1,x2, suffix)
  y1 = accumulate(+, x1+x2 .+ 0.1rand())
  y2 = accumulate(*, y1)
  y3 = accumulate(+, y2 ./ x1)
  mynames = Symbol.((:y1, :y2, :y3), "_$suffix")
  return (;zip(mynames, (y1,y2,y3))...)
end

d = DataFrame(x1=rand(100), x2=rand(100))

hcat(d, DataFrame(calc(d.x1, d.x2, "mycalc")))

```

---

_[View the full topic](https://discourse.julialang.org/t/prefixing-output-columns-which-are-returned-as-dataframe/98098)._
