mike_k
1
Dear community,
I want to read a csv file with several values including vectors to a data frame. My file looks like:
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
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:
mike_k
3
Thank you, I found this thread before but this was not satisfactory for my purposes. I found a different workaround:
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") )