我是一名F#的初学者,正在尝试使用CsvProvider并重现此处给出的示例:
http://fsharp.github.io/FSharp.Data/library/CsvProvider.html
因此,在F#交互环境中,我输入:
我的理解是CsvProvider基于CSV文件创建了一种类型,使得以后可以读取该文件或具有相同格式的不同文件/流。我认为我没有目录问题,因为如果文件在错误的目录中,该函数将返回一个错误。当msft被创建时,F#说NumberOfColumns=1,但这显然是错误的。这也不起作用。
我正在使用FSharp.Data库,像这样:(这是正确的版本吗?)
请帮忙!!!我已经尝试了几个小时了!谢谢!!! 编辑:以下是来自F#交互的完整日志。
>type Stocks = CsvProvider<"MSFT.csv">;;
type Stocks = CsvProvider<...>
> let msft = CsvProvider<"MSFT.csv">.GetSample();;
val msft : CsvProvider<...>
> msft;;
val it : CsvProvider<...> =
FSharp.Data.Runtime.CsvFile`1[System.Tuple`1[System.String]]
{Headers = Some [|"MSFT.csv"|];
NumberOfColumns = 1;
Quote = '"';
Rows = seq [];
Separators = ",";}
> let firstRow = msft.Rows |> Seq.head;;
System.ArgumentException: The input sequence was empty.
Parameter name: source
> at Microsoft.FSharp.Collections.SeqModule.Head[T](IEnumerable`1 source)
at <StartupCode$FSI_0044>.$FSI_0044.main@()
Stopped due to error
我的理解是CsvProvider基于CSV文件创建了一种类型,使得以后可以读取该文件或具有相同格式的不同文件/流。我认为我没有目录问题,因为如果文件在错误的目录中,该函数将返回一个错误。当msft被创建时,F#说NumberOfColumns=1,但这显然是错误的。这也不起作用。
> let msft = Stocks.Parse("MSFT.csv");;
val msft : CsvProvider<...>
> msft;;
val it : CsvProvider<...> =
FSharp.Data.Runtime.CsvFile`1[System.Tuple`1[System.String]]
{Headers = Some [|"MSFT.csv"|];
NumberOfColumns = 1;
Quote = '"';
Rows = seq [];
Separators = ",";}
我正在使用FSharp.Data库,像这样:(这是正确的版本吗?)
>#r "C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algo Stanford I\packages\FSharp.Data.2.2.5\lib\portable-net40+sl5+wp8+win8\FSharp.Data.dll"
--> Referenced 'C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algo Stanford I\packages\FSharp.Data.2.2.5\lib\portable-net40+sl5+wp8+win8\FSharp.Data.dll'
> open FSharp.Data;;
>
请帮忙!!!我已经尝试了几个小时了!谢谢!!! 编辑:以下是来自F#交互的完整日志。
Microsoft (R) F# Interactive version 14.0.23020.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
> #r "C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algo Stanford I\packages\FSharp.Data.2.2.5\lib\portable-net40+sl5+wp8+win8\FSharp.Data.dll"
open FSharp.Data;;
--> Referenced 'C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algo Stanford I\packages\FSharp.Data.2.2.5\lib\portable-net40+sl5+wp8+win8\FSharp.Data.dll'
> open FSharp.Data;;
> #I "C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algo Stanford I";;
--> Added 'C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algo Stanford I' to library include path
> let msft = CsvProvider<"MSFT.csv">.GetSample();;
val msft : CsvProvider<...>
> msft;;
val it : CsvProvider<...> =
FSharp.Data.Runtime.CsvFile`1[System.Tuple`1[System.String]]
{Headers = Some [|"MSFT.csv"|];
NumberOfColumns = 1;
Quote = '"';
Rows = seq [];
Separators = ",";}
> let msft = CsvProvider<"C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algo Stanford I\MSFT.csv">.GetSample();;
let msft = CsvProvider<"C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algo Stanford I\MSFT.csv">.GetSample();;
---------------------------------------------------------------------------------------------------^^^^^^^^^
stdin(7,100): error FS0039: The field, constructor or member 'GetSample' is not defined
> let msft = CsvProvider<"MSFT.csv">.GetSample();;
val msft : CsvProvider<...>
> let msft = CsvProvider<"C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algo Stanford I\MSFT.csv">.GetSample();;
let msft = CsvProvider<"C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Algo Stanford I\MSFT.csv">.GetSample();;
---------------------------------------------------------------------------------------------------^^^^^^^^^
stdin(9,100): error FS0039: The field, constructor or member 'GetSample' is not defined
>