DataFrames: hcat

Sorry for the newbie question. I want to do a hcat with a dataframe and an array, such that the column name is the name of the vector (rather than the default ‘X1’):

df = DataFrame(A = 1:4, B = [2,4,3,5 ])
newCol = [7,8,9,2]
newdf = hcat(df,newCol)

4×3 DataFrame
│ Row │ A     │ B     │ x1    │
│     │ Int64 │ Int64 │ Int64 │
├─────┼───────┼───────┼───────┤
│ 1   │ 1     │ 2     │ 7     │
│ 2   │ 2     │ 4     │ 8     │
│ 3   │ 3     │ 3     │ 9     │
│ 4   │ 4     │ 5     │ 2     │

How can I get ‘newCol’ as the column name instead of ‘x1’?

thanks!

instead of hcat, to add a new column, df.blah = newCol will do

2 Likes

Thanks! Sorry, new to Julia!

Nothing wrong with simple questions! And welcome to the julia discourse @bsmith

1 Like