[Haskell-cafe] Parsing a matrix table with Data.Frames

Tyson Whitehead twhitehead at gmail.com
Wed Jun 6 01:03:02 UTC 2018


Thanks Will,

I can see I wasn't clear at all.  The issue is that the animals are
not known ahead of time and can vary from file to file.  That is, the
normalized form of the data is

personal,animal,has
bill,cat,true
bill,dog,true
bill,goldfish,false
sue,cat,false
sue,dog,true
sue,goldfish,true
fred,cat,false
fred,dog,false
fred,goldfish,true

but the CSV files I have to read in are expressed in the matrix form

,cat,dog,goldfish
bill,true,true,false
sue,false,true,true
fred,false,false,true

Thanks!  -Tyson
On Tue, 5 Jun 2018 at 20:34, William Yager <will.yager at gmail.com> wrote:
>
> What's the issue you're running into? If it's confusion with the API, hopefully this example is helpful:
>
> > readRow (ParserOptions Nothing "," NoQuoting) "bill,true,true,false" :: Rec (Either Text) ["Name" :-> Text, "Cat" :-> Bool, "Dog" :-> Bool, "Goldfish" :-> Bool]
>
> {Right Name :-> "bill", Right Cat :-> True, Right Dog :-> True, Right Goldfish :-> False}
>
>
> Requires OverloadedStrings, DataKinds, TypeOperators.
>
>
> If you then want to extract data you can then do something like
>
>
> > rget (Proxy :: Proxy ("Name" :-> Text)) row
>
> Right Name :-> "bill"
>
>
> I assume there is some easier API for this (looks like via template haskell?). Seems kind of sad if there's no convenient way to do things without using TH, but I don't see anything obvious.
>
>
> --Will
>
>
>
> On Tue, Jun 5, 2018 at 5:58 PM, Tyson Whitehead <twhitehead at gmail.com> wrote:
>>
>> I have a case where some of my data is stored in CSV matrix form like this example of a table telling whether person i has pet j
>>
>> ,cat,dog,goldfish
>> bill,true,true,false
>> sue,false,true,true
>> fred,false,false,true
>>
>> I can't see any obvious way to read this sort of thing in with the Data.Frames package.  Would love to be told differently.
>>
>> Thanks!  -Tyson
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
>
>


More information about the Haskell-Cafe mailing list