6

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.

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
Felice Bruno
  • 195
  • 1
  • 12

1 Answers1

6

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.

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • Thank you, Thomas. In F# interactive, if I send the command: frame.Rows;; I have the values the same way as they are stored in the CSV file, I mean with decimal separator as "," instead of "." . Is it normal? – Felice Bruno Jun 16 '14 at 22:09
  • That sounds like the frame is loading the date as strings.. Does the CSV provider under the type to be float? – Tomas Petricek Jun 16 '14 at 23:32
  • Yes, Tomas, it's right. In FSI, frame.Rows prints data as they are stored in the file. If I print the content of frame.Rows.Values I can see the values in the correct form. Thank you for your help. – Felice Bruno Jun 20 '14 at 20:31