我试图将数组转换为Julia数据帧并添加列名。不幸的是,我发现的解决方案似乎无效。...
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"])
答案 0 :(得分:1)
您可以这样做:
using DataFrames
x = rand(4, 3)
df = DataFrame(x)
names!(df, [:Col_A, :Col_B, :Col_C])
或者仅仅是这个:
DataFrame(x, [:Col_A, :Col_B, :Col_C])
请注意,列名必须为Symbol
。如果将它们作为字符串,则可以像Symbol.(["Col_A", "Col_B", "Col_C"])
那样转换它们。