Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get Column Names as Symbols in Julia DataFrame

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…)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use propertynames from Base Julia to get what you want:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading