You may want to take a look at my library semantic-csv, which lets you cast 
rows as maps instead of vectors, so that you can group-by a column name 
instead of a positional index.

https://github.com/metasoarous/semantic-csv


On Saturday, July 7, 2018 at 11:07:50 PM UTC-7, Varun J.P wrote:
>
> Hi All, 
> Thanks for the tip to use (group-by last …)
> It was working fine until my csv file got updated. Now i am not sure abt 
> the number of columns in my csv. It could change in every row, but I still 
> need to group it with Heading 3 itself. 
>
> Example of my updated CSV is as below
>
> Heading1 Heading 2 Heading 3 Heading 4 Heading 5
>> abc 123 Value1 newValue 
>> def 234 Value1 anotherValue oneMoreValue
>> ghi dfgew Value1 aValue 
>> jkl 456 Value5 
>> pqr 567 Value5 
>> stu 678 value3 
>> vwx sdf value4 
>> yza 900 value4 
>
>  
> Now i cant use (group-by last ...) instead i tried using  
>
> (group-by (nth (nth testvector 0) 2) testvector) where testvector is a 
> vector of vector but is throwing an error 
>
>> "ClassCastException java.lang.String cannot be cast to clojure.lang.IFn  
>> clojure.core/group-by/fn--7011 
>> (core.clj:6870)" 
>
>
> Can someone suggest a different approch 
>
>
>
>
>
> On Tuesday, July 3, 2018 at 10:42:08 PM UTC+5:30, Philipp Neumann wrote:
>>
>> Hi.
>>
>> This is a job for (group-by last ...)
>>
>> Regards
>>
>> Varun J.P <varun...@gmail.com> schrieb am Di., 3. Juli 2018, 19:05:
>>
>>> My CSV file is something like the attached file which could have 'n' 
>>> number of line. I need to group by the values in the last column. 
>>> Current I believe the below code will return me a vector of vector. 
>>>
>>> (defn read-csv-file
>>>
>>>  [path]
>>>
>>>  (try
>>>
>>>    (with-open [input-file (io/reader path)]
>>>
>>>      (let [a_list (doall (map (comp first clojure-csv.core/parse-csv) (
>>> line-seq input-file)))]
>>>
>>>        (rest (into [] a_list))))
>>>
>>>    (catch Exception exception (throw exception))))
>>>
>>>
>>> i need to iterate through this vector of vector and create a new vector 
>>> of vector containing only elements of the first group, then in next 
>>> iteration i need the second set and so on. 
>>>
>>> Example CSV 
>>>
>>>> Heading1 Heading 2 Heading 3 
>>>> abc 123 Value1 
>>>> def 234 Value1 
>>>> ghi dfgew Value1 
>>>> jkl 456 Value5 
>>>> pqr 567 Value5 
>>>> stu 678 value3 
>>>> vwx sdf value4 
>>>> yza 900 value4 
>>>
>>>
>>>
>>> so when this CSV is parsed i will have something like 
>>> [
>>> [abc 123 Value1]
>>> [def 234 Value1]
>>> [ghi dfgew Value1]
>>> [jkl 456 Value5]
>>> [pqr 567 Value5]
>>> [stu 678 value3]
>>> [vwx sdf value4]
>>> [yza 900 value4]]
>>> So when i iterate through this i need to group the vector of vector by 
>>> the last column 
>>> so my first iteration output should be something like 
>>>
>>> [
>>> [abc 123 Value1]
>>> [def 234 Value1]
>>> [ghi dfgew Value1]]
>>> 2nd iteration should be 
>>> [
>>> [jkl 456 Value5]
>>> [pqr 567 Value5]]
>>> 3rd should be 
>>>
>>> [
>>> [stu 678 value3]] 
>>> and so on.
>>>
>>> How would i achieve this in clojure. is there any build in csv parsing 
>>> function
>>>
>>> Regards 
>>> JP
>>>
>>>
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send 
>>> an email to clojure+u...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to