# Data files with 'quotes' around the column names

**URL:** <https://discourse.julialang.org/t/data-files-with-quotes-around-the-column-names/17067>\
**Category:** Data\
**Created:** [November 1, 2018, 7:57pm UTC](https://discourse.julialang.org/t/data-files-with-quotes-around-the-column-names/17067 "2018-11-01T19:57:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)\
**Post date:** [November 1, 2018, 7:57pm UTC](https://discourse.julialang.org/t/data-files-with-quotes-around-the-column-names/17067/1 "2018-11-01T19:57:01Z")

</div>

I have data files, given to me by someone else, with the following format:

```
'col1','col2','col3'
1,2,3
4,5,6

```

And so on. CSV reads them just fine, and leaves me with a DataFrame that looks like

```
|Row | 'col1' | 'col2' | 'col3' |
_______________________________________
| 1 | 1. | 2. | 3. |
| 2 | 4. | 5. | 6. |

```

and so on. But I can’t access the columns, because the keys want to have a single-quote in them, but a single-quote is an invalid literal in a key name.

```
julia> data[:col1]
ERROR: KeyError: key :col1 not found
julia> data[:'col1']
ERROR: syntax: invalid character literal

```

Escaping the single-quote with a “\” also doesn’t work. What’s the magic incantation here?

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [November 1, 2018, 8:13pm UTC](https://discourse.julialang.org/t/data-files-with-quotes-around-the-column-names/17067/2 "2018-11-01T20:13:12Z")

</div>

Two options:

- you could specify `'` as the quotechar when reading, this would have the effect of removing the quotes when parsing, you would do this like `CSV.read(file; quotechar="'")`
- If you want to keep the single quotes for whatever reason, the right way to access the columns in the DataFrame is `data[Symbol("'col1'")]`

---

<div class="post-metadata">

**Author:** ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)\
**Post date:** [November 1, 2018, 8:21pm UTC](https://discourse.julialang.org/t/data-files-with-quotes-around-the-column-names/17067/3 "2018-11-01T20:21:38Z")

</div>

Neither of these appear to work:

```
julia> data = CSV.read(file; quotechar="'")
ERROR: TypeError: in Type, in typeassert, expected Union{Char, UInt8}, got String

```

and

```
julia> data[Symbol("'col1'")
ERROR: KeyError: key Symbol("'col1'") not found

```

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [November 1, 2018, 8:23pm UTC](https://discourse.julialang.org/t/data-files-with-quotes-around-the-column-names/17067/4 "2018-11-01T20:23:39Z")

</div>

Oops, my bad, the 1st option should be `CSV.read(file; quotechar='\'')`. Not sure what’s going on with the 2nd case. Can you post the output of `propertynames(data)`?

---

<div class="post-metadata">

**Author:** ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)\
**Post date:** [November 1, 2018, 8:29pm UTC](https://discourse.julialang.org/t/data-files-with-quotes-around-the-column-names/17067/5 "2018-11-01T20:29:27Z")

</div>

```
julia> CSV.read(file; quotechar='\'')
ERROR: LoadError: TypeError: in Type, in typeassert, expected Union{Char, UInt8}, got String

julia> propertynames(data)
4-element Array{Symbol,1}:
Symbol("'frame_num'")   
Symbol(" 'col1'")    
Symbol(" 'col2'")    
Symbol(" 'col3'")

```

---

<div class="post-metadata">

**Author:** ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)\
**Post date:** [November 1, 2018, 8:31pm UTC](https://discourse.julialang.org/t/data-files-with-quotes-around-the-column-names/17067/6 "2018-11-01T20:31:44Z")

</div>

Oh, wait; I made a mistake.

```
julia> CSV.read(file; quotechar="\'")
ERROR: LoadError: TypeError: in Type, in typeassert, expected Union{Char, UInt8}, got String

```

but

```
julia> CSV.read(file; quotechar='\'')

```

succeeds! Thanks.

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [November 2, 2018, 12:21am UTC](https://discourse.julialang.org/t/data-files-with-quotes-around-the-column-names/17067/7 "2018-11-02T00:21:48Z")

</div>

Glad the `quotechar` option worked. As for the DataFrame indexing, you can always do `data[x]` where `x` is one of the symbols in `propertynames(data)`, so it looks like in your case, the full column name was ` 'col1'`, with a single space before the single quote character.
