Combine(Merge) Columns

Programming & Julia newbie here: I have googled and searched the documentation and tried various ways to do this but I cannot come up with a solution and it seems so simple. Is there a way to combine two columns within a dataframe. See the below example, how could I make a column that would be named “C” and contain A:1 as it first row? The use case for me would be creating an ID column in an datafame that doesn’t contain one. I know there is a issue with A being a string and B being a Int is there a way to overcome that? Thanks in advance.

using DataFrames

df = DataFrame()

df.A = [“A”,“B”,“C”,“D”]

df.B = 1:4

display(df)

4×2 DataFrame
Row │ A B
│ String Int64
─────┼───────────────
1 │ A 1
2 │ B 2
3 │ C 3
4 │ D 4

Easiest solution:

df.C = string.(df.A, ":",  df.B)

transform solution

transform!(df, [:A, :B]  => ByRow((A, B) -> string(A, ":", B)) => :C)

DataFramesMeta solution:

@transform(df, C = string.(:A, ":", :B))
3 Likes

Thanks, pdeffebach that worked, appreciate the quick and thorough response.