# DataFrames: reading vector from \*.csv file to dataframe column

**URL:** <https://discourse.julialang.org/t/dataframes-reading-vector-from-csv-file-to-dataframe-column/29409>\
**Category:** General Usage\
**Created:** [October 2, 2019, 2:02pm UTC](https://discourse.julialang.org/t/dataframes-reading-vector-from-csv-file-to-dataframe-column/29409 "2019-10-02T14:02:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [October 2, 2019, 2:02pm UTC](https://discourse.julialang.org/t/dataframes-reading-vector-from-csv-file-to-dataframe-column/29409/1 "2019-10-02T14:02:19Z")

</div>

Dear community,

I want to read a csv file with several values including vectors to a data frame. My file looks like:

```julia
myInt; myString; myVec
1 ; foo ; [1,2,3]

```

The column `myVec` is, however, interpreted as string instead of vector if I read the file with  
`mydf = CSV.read( myfile.csv; delim=';' ) `.

Do you have any ideas how to cast that column to a vector-column, or for an easy workaround?

Thank you in advance.  
Michael

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 2, 2019, 3:08pm UTC](https://discourse.julialang.org/t/dataframes-reading-vector-from-csv-file-to-dataframe-column/29409/2 "2019-10-02T15:08:36Z")

</div>

Unless your file is huge, I would just read the last column as a string, then distribute to 3 columns later. See this topic for alternatives:

> [@Parse vector from string](https://discourse.julialang.org/t/parse-vector-from-string/10728):
>
> I can parse(Int, „123“) but I cannot find a simple way to parse(Vector{Int}, „[1, 2, 3]”). Is there a “canned” solution?

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [October 3, 2019, 12:59pm UTC](https://discourse.julialang.org/t/dataframes-reading-vector-from-csv-file-to-dataframe-column/29409/3 "2019-10-03T12:59:29Z")

</div>

Thank you, I found this thread before but this was not satisfactory for my purposes. I found a different workaround:

```julia
stripChar = (s, r) -> replace(s, Regex("[$r]") => "")

```

With this function I convert “[1,2,3]” to “1 2 3” (if r=“][,”) , which can be easily parsed to a vector by  
`parse.(Int, split("1 2 3") )`
