So let's say I have a CSV file with a header containing columns Population and Profit, and I'd like to work with it in F# interactive. I have the following code:
#r "../packages/FSharp.Data.1.1.10/lib/net40/FSharp.Data.dll"
open FSharp.Data
// load csv header
let cities = new CsvProvider<"cities.csv">()
// how to reach data
let firstRow = cities.Data |> Seq.head
let firstPopulation = firstRow.Population
let firstProfit = firstRow.Profit
I get an error from F# interactive:
error FS0039: The field, constructor or member 'Population' is not defined
This seems confusing to me, because intellisense in VS has no problem picking up this column from my data via a CSV type provider.
Also, I tried creating a program with the same type provider and it all works just fine. Like this:
open FSharp.Data
[<EntryPoint>]
let main argv =
use file = System.IO.File.CreateText("result.txt")
let csv = new CsvProvider<"cities.csv">()
for record in csv.Data do
fprintfn file "%A" record.Population
0
Am I missing something? Thanks for any answer.
Try this code