Chase CB
Chase CB

Reputation: 1627

Julia Parsing a CSV

Hope the evening is a more than hospitable one and you have traded your emacs terminal for some bonne-vivant Ralph Lauren catalog dinner party type scene. As for me, I'm trying to parse a CSV in Julia and things are deteriorating. Here is my code:

f2 = open("/Users/MacBookPro15/testnovo.csv", "r")

skip(f2, 736)

for line in eachline(f2)
    string_split = split(line, ",")
    println(string_split[1])      
end

Now if I substitute string_split[2] or anything other than [1] I get a BoundsError and it's rather frustrating because I need those items. Can anyone tell me how to avoid this?

Upvotes: 2

Views: 1394

Answers (2)

John Myles White
John Myles White

Reputation: 2929

Unfortunately, it looks like you need the DataStream abstraction, which we stopped including in DataFrames since not enough people worked on it to make it robust. The first 100 lines of https://github.com/JuliaStats/DataFrames.jl/blob/master/prototypes/datastream.jl should provide you with enough information to write your own streaming algorithm for working with CSV's.

Upvotes: 3

Ben Hamner
Ben Hamner

Reputation: 4725

Every time I hear "parsing a CSV" I want to duck and cover my ears, before I get flashbacks of a missing quote, or a 32-column line 98% of the way through a 33-column, 10GB csv file.

Fortunately, there are two useful functions that'll prevent you from rolling your own csv parser:

Upvotes: 7

Related Questions