# How to call a column in DataFrame that has a space in the name

**URL:** <https://discourse.julialang.org/t/how-to-call-a-column-in-dataframe-that-has-a-space-in-the-name/92687>\
**Category:** New to Julia\
**Tags:** question, dataframes\
**Created:** [January 8, 2023, 11:29pm UTC](https://discourse.julialang.org/t/how-to-call-a-column-in-dataframe-that-has-a-space-in-the-name/92687 "2023-01-08T23:29:58Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![phantom](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@phantom](https://discourse.julialang.org/u/phantom)\
**Post date:** [January 10, 2023, 7:53pm UTC](https://discourse.julialang.org/t/how-to-call-a-column-in-dataframe-that-has-a-space-in-the-name/92687/10 "2023-01-10T19:53:44Z")

</div>

Got it, thank you so much! This clears up a lot.

I apologize for not making the reference clear. The quotes come from Strings vs symbols in DataFrames.jl column indexing. Given my inadequate background I completely misunderstood the well written post.

I took the following examples to mean that a DataFrame column label was being stored as either a symbol or a string and must then be indexed in accordance with the type with which it was created.

( This sent me down a rabbit hole as to why the columns in @sijo 's example [here](https://discourse.julialang.org/t/run-multiple-instances-of-transform-on-specific-column-combinations-of-a-groupeddataframe-in-dataframes-mini-language/91736/22) could be accessed with a `string` as the `transform` operation output `NamedTuples` as new columns. Which lead to the above post.)

Now my understanding is that no matter how I create the DataFrame Column, it is stored in one way (a symbol?), and can be indexed freely with both symbols and strings.

Sorry don’t mean to create so much confusion on the discussion board. @bkamins book came out on amazon today so I should have a better understanding of things going forward.

> [@](#):
>
> # Strings vs symbols in DataFrames.jl
> 
> Column names in a `DataFrame` are labels. For this reason both symbols and strings are allowed to be used when referencing them without introducing an ambiguity. Here is an example. We start with strings:
> 
> ```julia
> julia> using DataFrames
> 
> julia> df = DataFrame("col1" => 1, "col 2" => 2)
> 1×2 DataFrame
> Row │ col1 col 2
> │ Int64 Int64
> ─────┼──────────────
> 1 │ 1 2
> 
> julia> df."col1"
> 1-element Vector{Int64}:
> 1
> 
> julia> df."col 2"
> 1-element Vector{Int64}:
> 2
> 
> julia> df[:, "col1"]
> 1-element Vector{Int64}:
> 1
> 
> julia> df[:, "col 2"]
> 1-element Vector{Int64}:
> 2
> 
> ```
> 
> Now we try the same with symbols:
> 
> ```julia
> julia> df = DataFrame(:col1 => 1, Symbol("col 2") => 2)
> 1×2 DataFrame
> Row │ col1 col 2
> │ Int64 Int64
> ─────┼──────────────
> 1 │ 1 2
> 
> julia> df.col1
> 1-element Vector{Int64}:
> 1
> 
> julia> getproperty(df, Symbol("col 2"))
> 1-element Vector{Int64}:
> 2
> 
> julia> df[:, :col1]
> 1-element Vector{Int64}:
> 1
> 
> julia> df[:, Symbol("col 2")]
> 1-element Vector{Int64}:
> 2
> 
> ```
> 
> We now see the first difference, that we have already discussed. If column names are all valid variable names symbols are more convenient, however, if they are not (e.g. contain spaces) then using strings is more convenient. As an extreme case, note that the convenience syntax for `getproperty` using`.` accessor does not work for symbols containing spaces and we need to do an explicit `getproperty` call.

But now I understand that all columns are stored the same way

---

_[View the full topic](https://discourse.julialang.org/t/how-to-call-a-column-in-dataframe-that-has-a-space-in-the-name/92687)._
