Home > Mobile >  Get Column Names as Symbols in Julia DataFrame
Get Column Names as Symbols in Julia DataFrame

Time:02-14

I have a DataFrame

df = DataFrame(a=1:4,b=5:8, c=["a", "b", "c", "d"])
4×3 DataFrame
 Row │ a      b      c      
     │ Int64  Int64  String 
─────┼──────────────────────
   1 │     1      5  a
   2 │     2      6  b
   3 │     3      7  c
   4 │     4      8  d

I can get the column names as a Vector of Strings with

names(df)
3-element Vector{String}:
 "a"
 "b"
 "c"

Is there a built-in way of getting it as Symbols? (I thought, I've seen this somewhere, but I can't remember where...)

CodePudding user response:

Use propertynames from Base Julia to get what you want:

julia> propertynames(df)
3-element Vector{Symbol}:
 :a
 :b
 :c
  • Related