2014-01-11 70 views
1

我試圖實現一個Deedle解決方案,用於從@migueldeicaza在F#中實現的小挑戰在Python中使用http://t.co/4YFXk8PQaU和完成的任務。csv源數據可從鏈接獲得。Deedle IndexRows type annotations

開始很簡單,但現在,當試圖根據一系列浮點值進行排序時,我正在努力理解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個最大值...也許我可以爲自己工作...

+0

當然 - 但這裏對語法的變化導致一些完全不同的錯誤,告訴我,我知道,我只是不知道如何將類型註釋添加到deedle列:) –

+0

它看起來就像你不需要這裏的''一樣 - https://stackoverflow.com/questions/20482404/can-i-sort-a-deedle-frame –

+0

其實,你說得很對,我在找小傻瓜! bodyCountData |> Frame.indexRows「DeathsPerMinute」是合法的 - 但它仍然失敗,因爲DeathsPerMinute系列具有重複值。我插入了類型註釋,因爲它在函數的描述中作爲一個建議出現。有點傻。所以,我需要想辦法處理重複。 –

回答