简体   繁体   中英

F# CsvProvider cant find member in Row error FS0039

I try example from Isaac Abraham book "get programming with F#". In it I simply import csv file into F# script and try to do simple operations.

#r "nuget: FSharp.Data"

open FSharp.Data
type Football = CsvProvider<"FootballResults.csv">
let data = Football.GetSample().Rows|> Seq.toArray
let work = data |> Seq.filter (fun i -> i.``Full Time Away Goals`` > i.``Half Time Away Goals``)
let print = work |> Seq.take 10 |> Seq.map (fun i -> i.``Half Time Home Goals``) 
let print2 = print |> Seq.iter (fun i -> printfn "%i" i)

I get an error:

script.fsx(6,43): error FS0039: The type 'Row' does not define the field, constructor or member 'Full Time Away Goals'.

I am pretty much stuck here. Csv file is from here and I can see fields name in intellisense window, but no matter what I try, I cant do any work with fields.

I use VsCode with

Microsoft (R) F# Interactive version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

Update:

I used absolute path and it worked; but I must say I have script and csv file in same directory.

Directory of C:\study\fsharp_Study\csv

20.01.2021  15:20    <DIR>          .
20.01.2021  15:20    <DIR>          ..
20.01.2021  15:19            26 446 FootballResults.csv
21.01.2021  08:29               373 script.fsx
               2 File(s)         26 819 bytes
               2 Dir(s)  131 790 934 016 bytes free 

The problem is that F# can't find "FootballResults.csv" at runtime, because it's located in a different directory from the one that the script is running in. The easiest way to solve this is to specify the full path to the.csv file:

type Football = CsvProvider<"C:\My\Full\Path\FootballResults.csv">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM