# CSV file reading Arrays as String in CSVFiles.jl and CSV.jl

**URL:** <https://discourse.julialang.org/t/csv-file-reading-arrays-as-string-in-csvfiles-jl-and-csv-jl/45331>\
**Category:** General Usage\
**Tags:** data, csv\
**Created:** [August 21, 2020, 5:07pm UTC](https://discourse.julialang.org/t/csv-file-reading-arrays-as-string-in-csvfiles-jl-and-csv-jl/45331 "2020-08-21T17:07:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stochastic\_guy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stochastic_guy/32/9877_2.png) [@stochastic\_guy](https://discourse.julialang.org/u/stochastic_guy)\
**Post date:** [August 21, 2020, 5:07pm UTC](https://discourse.julialang.org/t/csv-file-reading-arrays-as-string-in-csvfiles-jl-and-csv-jl/45331/1 "2020-08-21T17:07:58Z")

</div>

I am trying to read a CSV file that has a column of Arrays. While reading it via `CSVFiles.jl` and `CSV.jl` the column of arrays are loaded as String.

This is how that specific column values look like in the CSV File  
 ![q_meta](https://global.discourse-cdn.com/julialang/original/3X/b/3/b31ff11bdd4edfc3eab714266ac9a3bee5d5edeb.jpeg)

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [August 21, 2020, 5:20pm UTC](https://discourse.julialang.org/t/csv-file-reading-arrays-as-string-in-csvfiles-jl-and-csv-jl/45331/2 "2020-08-21T17:20:55Z")

</div>

That looks like a perfect use case for jsonlines [Initial version of my first package: A JSON Lines reader](https://discourse.julialang.org/t/initial-version-of-my-first-package-a-json-lines-reader/44552)

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [August 21, 2020, 5:25pm UTC](https://discourse.julialang.org/t/csv-file-reading-arrays-as-string-in-csvfiles-jl-and-csv-jl/45331/3 "2020-08-21T17:25:03Z")

</div>

At the moment the package assumes that the lines are json objects (“{…}”) rather than json arrays (“[…]”) but I can work on that

---

<div class="post-metadata">

**Author:** ![stochastic\_guy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stochastic_guy/32/9877_2.png) [@stochastic\_guy](https://discourse.julialang.org/u/stochastic_guy)\
**Post date:** [August 21, 2020, 8:39pm UTC](https://discourse.julialang.org/t/csv-file-reading-arrays-as-string-in-csvfiles-jl-and-csv-jl/45331/4 "2020-08-21T20:39:53Z")

</div>

I think I found the solution.  
Used the following code:

`map(x->parse.(Int64,x),[split(chop(elements, head=1), ",") for elements in q_meta[:SubjectId] ])`

where `SubjectId` is the column name and `q_meta` is the csv file loaded as a data frame.

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [August 21, 2020, 11:01pm UTC](https://discourse.julialang.org/t/csv-file-reading-arrays-as-string-in-csvfiles-jl-and-csv-jl/45331/5 "2020-08-21T23:01:53Z")

</div>

Files with arrays similar to [the first example on the JSONLines website](http://jsonlines.org/examples/) can now be read using the `readarrays(file)` function. I plan to eventually merge this into the `readfile` function but I have to clean up the code first.  
Check out:

[https://github.com/danielw2904/JSONLines.jl/commit/7afa32f7fbc0921c489603c8290d00d61ffc475f](https://github.com/danielw2904/JSONLines.jl/commit/7afa32f7fbc0921c489603c8290d00d61ffc475f)
