Concatenate two csv columns in julia

Hi all,

I am trying to replicate the excel function concat in julia.

I have two columns A and B. I am trying to concatenate the values in these columns and produce a single column with the values in columns A and columns B concatenated with “:” in between.

Column A and Column B are of the same size A (1000, 1) and B(1000, 1).

I have tried the below code which isn’t given me the required outcome.

using CSV
using DataFrames

columnA = CSV.read(location, DataFrame; select = columnA) columnB = CSV.read(location, DataFrame; select = columnB])

y = DataFrame(x1 = columnA, x2 = columnB)

CONCAT = [“(r[:x1]):(r[:x2])” for r in eachrow(y)]

Any ideas how to change this to return a new column C with A and B concatented with “:” in between?

y = DataFrame(x1 = columnA, x2 = columnB)

This line shouldn’t work, since columnA and columnB are both DataFrames.

Where are you getting an error?

My issue is that the dataframe produced isnt what I expect, I would expect the new dataframe to be a (1000,2) but its actually coming out as (1, ).

Not sure what the best way to concatenate the two columns is?

I’ve also printed ColumnA and ColumnB to make sure the data has been extracted from the csv properly and it has.

I just cant seem to concatenate them into one dataframe

If they are vectors, you can concatinate them using broadcasting:

C = string.(colA, ":", colB)

Or with DataFrames

df[!, "C"] = string.(df[!, "colA"], ":", df[!. "colB"])
4 Likes

Thank you!

1 Like