如何将数据从FSharp.Data.CsvProvider传递给Deedle.Frame?

时间:2020-12-07 01:38:05

I'm trying to pass data from a FSharp.Data.CsvProvider to a Deedle.Frame.

我正在尝试将数据从FSharp.Data.CsvProvider传递给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.

我在F#中几乎是新手,我需要将一些CSV文件从文化“it-IT”转换为“en-US”,这样我才能使用这些数据。

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).

我找到了Deedle,我想学习如何使用它,但是我无法直接转换Deedle中的CSV文件中的数据(至少是用F#交互式打印的)。

I noticed that the CsvProvider makes the conversion, but after some days of attempts I am not able to pass the data.

我注意到CsvProvider进行了转换,但经过几天的尝试后,我无法传递数据。

1 个解决方案

#1


5  

I believe that Deedle should be able to deal with CSV files that use non-US culture:

我相信Deedle应该能够处理使用非美国文化的CSV文件:

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:

也就是说,如果您出于某种原因想要使用CSV类型提供程序,可以使用:

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.

这使用Frame.ofRecords,它从任何.NET集合创建数据框,并将对象的属性扩展为列。 CSV提供程序将数据表示为元组,因此这不会正确命名标题 - 但Frame.indexColsWith函数允许您为标题明确命名。

#1


5  

I believe that Deedle should be able to deal with CSV files that use non-US culture:

我相信Deedle应该能够处理使用非美国文化的CSV文件:

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:

也就是说,如果您出于某种原因想要使用CSV类型提供程序,可以使用:

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.

这使用Frame.ofRecords,它从任何.NET集合创建数据框,并将对象的属性扩展为列。 CSV提供程序将数据表示为元组,因此这不会正确命名标题 - 但Frame.indexColsWith函数允许您为标题明确命名。