1
votes

I am trying to convert an array to a Julia dataframes and adding column names. Unfortunately, the solutions that I found doesn't seem to work....

using DataFrames

x = rand(4, 3)
df = convert(DataFrame, x)

# This doesn't work:

rename!(df, ["Col_A", "Col_B", "Col_C"])
names(df) = ["Col_A", "Col_B", "Col_C"])
1

1 Answers

3
votes

You can do this:

using DataFrames

x = rand(4, 3)
df = DataFrame(x)
names!(df, [:Col_A, :Col_B, :Col_C])

or simply this:

DataFrame(x, [:Col_A, :Col_B, :Col_C])

Notice that column names have to be Symbol. If you have them as strings you can convert them like this Symbol.(["Col_A", "Col_B", "Col_C"]).