I would like to modify the examples given user=> (def csv (parse-csv "1,2,3\n4,5,6\n7,8,9")) #'user/csv user=> (nth (nth csv 1) 2) ;; Get 2nd row, last column. "6" user=> (-> csv (nth 1) (nth 2)) ;; Another way to do it. "6" user=> (defn get-column [parsed-csv col] (map #(nth % col) parsed-csv)) ;; Function to return a given column. #'user/get-column user=> (get-column csv 1) ;; Get second column as a sequence. ("2" "5" "8")
to read in a .csv file, and then perform the functions on the parsed csv file, but I am getting clojure.lang.LazySeq cannot be cast to clojure.lang.IFn. How do I do this properly? Thanks. On Jun 16, 12:20 am, David Santiago <david.santi...@gmail.com> wrote: > Here's a repl session that will hopefully demonstrate how to do a few > things, including pull out an entire column. Just remember the library > turns CSVs into regular clojure data structures, so getting the data > you want out of the return value of the parse is just about indexing > into vectors. > > user=> (use 'clojure-csv.core) > nil > user=> (def csv (parse-csv "1,2,3\n4,5,6\n7,8,9")) > #'user/csv > user=> (nth (nth csv 1) 2) ;; Get 2nd row, last column. > "6" > user=> (-> csv (nth 1) (nth 2)) ;; Another way to do it. > "6" > user=> (defn get-column [parsed-csv col] (map #(nth % col) > parsed-csv)) ;; Function to return a given column. > #'user/get-column > user=> (get-column csv 1) ;; Get second column as a sequence. > ("2" "5" "8") > > - David > > On Wed, Jun 15, 2011 at 9:58 PM, octopusgrabbus > > > > > > > > <octopusgrab...@gmail.com> wrote: > > I've got to go back and look at your documentation. I'm not sure how > > to pull the columns out of each row. > > > On Jun 15, 5:04 pm, David Santiago <david.santi...@gmail.com> wrote: > >> I'm afraid I don't understand the question. What do you mean > >> "positionally?" When it parses the CSV file, it gives you back a > >> stream of rows, each row being a vector of the contents of each cell > >> of the CSV. If you are interested in cells at a given row/column, you > >> should be able to count into those vectors fairly naturally... > > >> - David > > >> On Wed, Jun 15, 2011 at 2:08 PM, octopusgrabbus<octopusgrab...@gmail.com> > >> wrote: > >> > Is it possible to use clojure-csv to extract data positionally in > >> > a .csv file, or should I use BufferedReader to read each line lazily > >> > and apply splitting the line up into fields by delimiter? > > >> > Thanks. > >> > cmn > > >> > -- > >> > You received this message because you are subscribed to the Google > >> > Groups "Clojure" group. > >> > To post to this group, send email to clojure@googlegroups.com > >> > Note that posts from new members are moderated - please be patient with > >> > your first post. > >> > To unsubscribe from this group, send email to > >> > clojure+unsubscr...@googlegroups.com > >> > For more options, visit this group at > >> >http://groups.google.com/group/clojure?hl=en > > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clojure@googlegroups.com > > Note that posts from new members are moderated - please be patient with > > your first post. > > To unsubscribe from this group, send email to > > clojure+unsubscr...@googlegroups.com > > For more options, visit this group at > >http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en