Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass data from a FSharp.Data.CsvProvider to a Deedle.Frame?

I'm trying to pass data from a FSharp.Data.CsvProvider to a Deedle.Frame.

I'm almost new in F#, and I need to convert some CSV files from culture "it-IT" to "en-US", so I can use the data.

I found Deedle, and I want to learn how to use it, but I was not able to directly convert the data from a CSV file in Deedle (at least is what is printed in F# interactive).

I noticed that the CsvProvider makes the conversion, but after some days of attempts I am not able to pass the data.

like image 842
Felice Bruno Avatar asked Jun 16 '14 21:06

Felice Bruno


1 Answers

I believe that Deedle should be able to deal with CSV files that use non-US culture:

let frame = Frame.ReadCsv("C:\\test.csv", culture="it-IT")

That said, if you want to use the CSV type provider for some reason, you can use:

let cs = new CsvProvider<"C:/data/fb.csv">()

cs.Rows
|> Frame.ofRecords
|> Frame.indexColsWith cs.Headers.Value

This uses Frame.ofRecords which creates a data frame from any .NET collection and expands the properties of the objects as columns. The CSV provider represents data as tuples, so this does not name the headers correctly - but the Frame.indexColsWith function lets you name the headers explicity.

like image 57
Tomas Petricek Avatar answered Nov 15 '22 08:11

Tomas Petricek