How to "label" DataFrame categorical column?

You can do e.g. (to show the use of DataFramesMeta.jl):

julia> using DataFramesMeta

julia> @transform(df, :x = recode(:x, 1 => "one", 2 => "two", 3 => "tree"))
3×1 DataFrame
 Row │ x
     │ Cat…
─────┼──────
   1 │ one
   2 │ two
   3 │ tree

the point is that you cannot replace integers with strings in place as it would change the element type of the container. You need to create a new recoded categorical vector.

If you want just to get the vector use:

julia> recode(df.x, 1 => "one", 2 => "two", 3 => "tree")
3-element CategoricalArray{String,1,UInt32}:
 "one"
 "two"
 "tree"
2 Likes