# Adding special characters to data frame column names

**URL:** https://discourse.julialang.org/t/adding-special-characters-to-data-frame-column-names/23757
**Category:** General Usage
**Tags:** dataframes
**Created:** [May 1, 2019, 10:19pm UTC](https://discourse.julialang.org/t/adding-special-characters-to-data-frame-column-names/23757 "2019-05-01T22:19:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jayce\_ram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayce_ram/32/3977_2.png) [@jayce\_ram](https://discourse.julialang.org/u/jayce_ram)
#### Post date: [May 1, 2019, 10:19pm UTC](https://discourse.julialang.org/t/adding-special-characters-to-data-frame-column-names/23757/1 "2019-05-01T22:19:38Z")

</div>

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 :

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

```

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [May 1, 2019, 10:43pm UTC](https://discourse.julialang.org/t/adding-special-characters-to-data-frame-column-names/23757/2 "2019-05-01T22:43:06Z")

</div>

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

```julia
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 `Pair`s of `Symbol`s and `Vector`s:

```julia
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 │

```

---

<div class="post-metadata">

### Author: ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)
#### Post date: [May 1, 2019, 10:49pm UTC](https://discourse.julialang.org/t/adding-special-characters-to-data-frame-column-names/23757/3 "2019-05-01T22:49:04Z")

</div>

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

```julia
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 │

```

---

<div class="post-metadata">

### Author: ![jayce\_ram](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jayce_ram/32/3977_2.png) [@jayce\_ram](https://discourse.julialang.org/u/jayce_ram)
#### Post date: [May 2, 2019, 1:40pm UTC](https://discourse.julialang.org/t/adding-special-characters-to-data-frame-column-names/23757/4 "2019-05-02T13:40:23Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)
#### Post date: [May 2, 2019, 5:48pm UTC](https://discourse.julialang.org/t/adding-special-characters-to-data-frame-column-names/23757/5 "2019-05-02T17:48:00Z")

</div>

> [@rdeits](#):
>
> DataFrame([:TypeProduct =\> [1,2,3], Symbol(“Price - $/l”) =\> [4,5,6]])

@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
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 │

```
