Adding special characters to data frame column names

I would like to create a data frame column name like " Price - $/l " but i can’t find the right syntax…
Anyone knows how I could create my dataframe column name that contains special characters like "/’ ? Thanks a lot !!

My example just below :

df = DataFrame(TypeProduct=[], Price - $/l =[])

You can create a symbol (even one which is not a valid identifier) with the Symbol constructor:

julia> Symbol("Price - \$/l")
Symbol("Price - \$/l")

(note the \ before $. Without that, Julia will treat the $ as a string interpolation).

You can also create a DataFrame from a collection of Pairs of Symbols and Vectors:

julia> DataFrame([:TypeProduct => [1,2,3], Symbol("Price - \$/l") => [4,5,6]])
3×2 DataFrame
│ Row │ TypeProduct │ Price - $/l │
│     │ Int64       │ Int64       │
├─────┼─────────────┼─────────────┤
│ 1   │ 1           │ 4           │
│ 2   │ 2           │ 5           │
│ 3   │ 3           │ 6           │
2 Likes

Alternatively you can use the fact that when DataFrame is constructed from an AbstractDict keys can be strings, so you can write:

julia> DataFrame(Dict("TypeProduct" => [1,2,3], "Price - \$/l" => [4,5,6]))
3×2 DataFrame
│ Row │ Price - $/l │ TypeProduct │
│     │ Int64       │ Int64       │
├─────┼─────────────┼─────────────┤
│ 1   │ 4           │ 1           │
│ 2   │ 5           │ 2           │
│ 3   │ 6           │ 3           │

julia> using DataStructures

julia> DataFrame(OrderedDict("TypeProduct" => [1,2,3], "Price - \$/l" => [4,5,6]))
3×2 DataFrame
│ Row │ TypeProduct │ Price - $/l │
│     │ Int64       │ Int64       │
├─────┼─────────────┼─────────────┤
│ 1   │ 1           │ 4           │
│ 2   │ 2           │ 5           │
│ 3   │ 3           │ 6           │
2 Likes

Thanks for your help @rdeits and @bkamins ! By information, I can’t solve my problem by using the solution presented by @rdeits, the code didn’t work in my Julia version, I have not updated my version yet and I got a message error by only reproducing its solution. The solution that matched to my problem was provided by the user @bkamins.

@jayce_ram Remove [ and ] in the solution of @rdeits and it will work on older versions of the DataFrames.jl package like this (in other word pass a sequence of Pair positional arguments not a vector of them):

julia> DataFrame(:TypeProduct => [1,2,3], Symbol("Price - \$/l") => [4,5,6])
3×2 DataFrame
│ Row │ TypeProduct │ Price - $/l │
│     │ Int64       │ Int64       │
├─────┼─────────────┼─────────────┤
│ 1   │ 1           │ 4           │
│ 2   │ 2           │ 5           │
│ 3   │ 3           │ 6           │
1 Like