1

我试图为来自@migueldeicaza 的小挑战实施 Deedle 解决方案,以在 F# 中完成在http://t.co/4YFXk8PQaU,带有 python 和 R。 csv 源数据可从链接获得。

开始很简单,但现在,在尝试基于一系列浮点值进行排序时,我正在努力理解 IndexRows 类型注释的语法。

#I "../packages/FSharp.Charting.0.90.5"
#I "../packages/Deedle.0.9.12"
#load "FSharp.Charting.fsx"
#load "Deedle.fsx"

open System
open Deedle
open FSharp.Charting

let bodyCountData = Frame.ReadCsv(__SOURCE_DIRECTORY__ + "/film_death_counts.csv")
bodyCountData?DeathsPerMinute <- bodyCountData?Body_Count / bodyCountData?Length_Minutes

// select top 3 rows based upon default ordinal indexer
bodyCountData.Rows.[0..3]

// create a new frame indexed and ordered by descending number of screen deaths per minute
let bodyCountDataOrdered =
    bodyCountData
    |> Frame.indexRows <float>"DeathsPerMinute" // uh oh error here - I'm confused

而且因为我无法弄清楚这种语法......各种消息,如:

Error   1   The type '('a -> Frame<'c,Frame<int,string>>)' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface. See also c:\wd\RPythonFSharpDFChallenge\RPythonFSharpDFChallenge\EvilMovieQuery.fsx(18,4)-(19,22).    c:\wd\RPythonFSharpDFChallenge\RPythonFSharpDFChallenge\EvilMovieQuery.fsx  19  8   RPythonFSharpDFChallenge
Error   2   Type mismatch. Expecting a
    'a -> Frame<'c,Frame<int,string>>    
but given a
    'a -> float    
The type 'Frame<'a,Frame<int,string>>' does not match the type 'float'  c:\wd\RPythonFSharpDFChallenge\RPythonFSharpDFChallenge\EvilMovieQuery.fsx  19  25  RPythonFSharpDFChallenge
Error   3   This expression was expected to have type
    bool    
but here has type
    string  c:\wd\RPythonFSharpDFChallenge\RPythonFSharpDFChallenge\EvilMovieQuery.fsx  19  31  RPythonFSharpDFChallenge

编辑:想想这个......无论如何,在测量的浮点数上建立索引是一件愚蠢的事情 - 现实世界数据中的重复值和缺失值。所以,我想知道对此会有什么更明智的方法。我仍然需要找到 25 个最大值......也许我可以自己解决这个问题......

4

1 回答 1

0

使用 Deedle 1.0,您可以对任意列进行排序。

见:http ://bluemountaincapital.github.io/Deedle/reference/deedle-framemodule.html#section7

于 2014-05-30T13:25:04.210 回答