[英]F# CsvProvider cant find member in Row error FS0039
I try example from Isaac Abraham book "get programming with F#".我尝试了 Isaac Abraham 书中“使用 F# 进行编程”中的示例。 In it I simply import csv file into F# script and try to do simple operations.
在其中我只是将 csv 文件导入 F# 脚本并尝试做简单的操作。
#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.
Csv 文件来自这里,我可以在智能感知 window 中看到字段名称,但无论我尝试什么,我都无法对字段进行任何处理。
I use VsCode with我使用 VsCode
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.
但我必须说我在同一目录中有脚本和 csv 文件。
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:问题是 F# 在运行时找不到“FootballResults.csv”,因为它位于与运行脚本的目录不同的目录中。解决此问题的最简单方法是指定.csv 的完整路径文件:
type Football = CsvProvider<"C:\My\Full\Path\FootballResults.csv">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.