Reputation: 137
I have a code where I have the following frame and filter rows as follows:
let dfff=
[ "year" => series [ 1 => 1990.0; 2 => 1991.00; 3 => 1992.0; 4 => 1993.0]
"gold" => series [ 1 => 10.0; 2 => 10.00; 3 => 15.0; 4 => 20.0]
"silver" => series [ 1 => 20.0; 2 => 30.00; 3 => 45.0; 4 => 55.0] ]
|> frame
let dfff2 = dfff |> Frame.filterRows (fun key row -> row?year <= 1992.0 )
Why do I have to write key in
Frame.filterRows (fun key row -> row?year <= 1992.0)
if my function only depends on row? What role does key play here? I will appreciate if anybody could explain me the logic. Thanks!
Upvotes: 1
Views: 453
Reputation: 243106
In Deedle, frames have row keys and column keys. In your case, you have Frame<int, string>
meaning that the row keys are integers (just numbers) and column keys are strings (column names) - but you might also have dates or other more interesting things as row keys.
The filterRows
function gives you the row key together with row data. The key
parameter is just the row key - in your case, this is (uninteresting) int index, but it might be e.g. useful date in other scenarios.
F# lets you write _
to explicitly ignore the value:
let dfff2 = dfff |> Frame.filterRows (fun _ row -> row?year <= 1992.0 )
In the Series
module, we have Series.filter
and Series.filterValues
where the first one gives you key & value and the second one gives you just the value. So, we could follow the same pattern and add Frame.filterRowValues
.
This would actually be quite easy, so if you want to contribute, please send a pull request with a change somewhere around here :-).
Upvotes: 3