The function seriesToFrame
takes a Series of the type <Key,'a>
and turnes it into a Frame of the type <int,string>
.
The function applies the value part of the Key
as values in its own Column called Values
. The key part of the Key
is turned into column names
To get the Key type back in the Frame you can vor example index it with the indexWithColumnValues
function
let newKeyTest str a = Key().addCol(str,a)
let seriesForFrame:Series<Key,_> =
[
(newKeyTest "One" 4.).addCol ("Two",2.), 1.
(newKeyTest "One" 2.).addCol ("Two",5.), 2.
]
|>series
let seriesToFrameTest = seriesToFrame seriesForFrame
seriesToFrameTest.Print()
One Two Value
0 -> 4 2 1
1 -> 2 5 2
|
The function indexWithColumnValues
takes the column keys defined in a Series that is provided and values in these columns and applies them as Keys into the Rows. The original column keys are maintained.
let seriesToFrameTestIndexed = seriesToFrame seriesForFrame |> indexWithColumnValues ["One"; "Two"]
seriesToFrameTestIndexed.Print()
One Two Value
One: 4
Two: 2
-> 4 2 1
One: 2
Two: 5
-> 2 5 2
|
The getColumn
function gets a single column of the frame. It needs the exact name of the column key.
let getColumn2: Series<Key,string> = getColumn "Two" seriesToFrameTestIndexed
getColumn2.Print()
One: 4
Two: 2
-> 2
One: 2
Two: 5
-> 5
|
The function rowKeyoColumns
shifts the row keys of type Key into the columns and become strings. The value part of the Key type gets put into the new columns
let exmpColMajorFrameTwo =
frame [
( "c1,T1,r1" )=> series [(newKeyTest"row1" 1.).addCol ("row2", 3.),3.]
( "c2,T1,r1" )=> series [(newKeyTest"row1" 10.).addCol("row2" ,100.),100.]
]
exmpColMajorFrameTwo.Print()
let testRowToColumnKey = rowKeyToColumns exmpColMajorFrameTwo
testRowToColumnKey.Print()
c1,T1,r1 c2,T1,r1
row1: 1
row2: 3
-> 3 <missing>
row1: 10
row2: 100
-> <missing> 100
row1 row2 c1,T1,r1 c2,T1,r1
0 -> 1 3 3 <missing>
1 -> 10 100 <missing> 100
|
The function createFilter
needs a function that takes a input and gives a bool and a series of <Key,_>
(most often a single column). It then gives a Series of <Key,bool>
that can be used in later functions as filter.
let boolFunction a =
if a > 1. then true
else false
let letsCreateAFilter = createFilter boolFunction seriesForFrame
letsCreateAFilter.Print()
One: 4
Two: 2
-> False
One: 2
Two: 5
-> True
|
The transform
function needs a function that turns 'a into 'b and a series that has the <Key,_>
type (most often a single column) to transform your data
let transformFuction a=
if a = 1. then 0.
else a
let letsTransformSomeSeries = transform transformFuction seriesForFrame
letsTransformSomeSeries.Print()
One: 4
Two: 2
-> 0
One: 2
Two: 5
-> 2
|
the zip
function needs a function that takes two parameters and two series of type <Keytype,'a>
(most often a single column) which then zippes depending on the function used
let getColumnOne = exmpColMajorFrameTwo|> getColumn<float> "c1,T1,r1"
let getColumnTwo= exmpColMajorFrameTwo|> getColumn<float> "c2,T1,r1"
let zipped = zip (fun x y -> x / y) getColumnOne getColumnTwo
zipped.Print()
row1: 1
row2: 3
-> <missing>
row1: 10
row2: 100
-> <missing>
|
dropKeyColumns
and dropAllKeyColumnsBut
takes a sequence of column keys and a Key.
the sequences should in the first case contain all columns that need to be dropped and in the second option all columns that will be kept
// the Key can contain any number of keys from which keys can be dropped
let seriesForPropertyDrop = seq ["c1,T1,r1";"c2,T1,r1";"c2,T1,r3"]
let keyForPropertyDrop = ( newKeyTest "c1,T1,r1" 0).addCol ("LLLL",9)
let dropsProperty = dropKeyColumns seriesForPropertyDrop keyForPropertyDrop
let dropsAllPropBut =dropAllKeyColumnsBut seriesForPropertyDrop keyForPropertyDrop
printfn("%O")dropsProperty
printfn("%O") dropsAllPropBut
The groupTransform
functions takes a function of op :'a [] -> 'a -> 'b
, in this case the dropAllKeyColumnsBut
function a Seq<string> and a Series<'KeyType, 'a>
.
Depending on the function used the series gets transformed. While the groupFilter
is a special version of it that uses groupTransform
and needs
op :'a [] -> 'a -> bool
.
let seriesForFrameFloat:Series<Key,_> =
[
(newKeyTest "Two" 4).addCol ("One",2), 1.
(newKeyTest "Two" 2).addCol ("One",5), 2.
(newKeyTest "Two" 2).addCol ("One",7), 3.
]
|>series
let seriesForPropertyDropMod = seq ["Two"]
let operation =
fun (x:seq<float>) ->
let m = Seq.mean x
fun x -> x - m
let tryGroupsTransform = groupTransform operation dropAllKeyColumnsBut seriesForPropertyDropMod seriesForFrameFloat
tryGroupsTransform.Print()
let opFilter=
fun values ->
let mean = Seq.mean values
(fun values -> values <= mean)
let tryGroupsFilter = createGroupFilter opFilter dropAllKeyColumnsBut seriesForPropertyDropMod seriesForFrameFloat
tryGroupsFilter.Print()
Two: 4
One: 2
-> 0
Two: 2
One: 5
-> -0.5
Two: 2
One: 7
-> 0.5
Two: 4
One: 2
-> True
Two: 2
One: 5
-> True
Two: 2
One: 7
-> False
|
The aggregate
function uses a created filter to filter the given series of <Key,'a>
and everything that is not true is dropped. In this case only the first row is kept.
Then either dropKeyColumns
or dropAllKeyColumnsBut
or a user defined function is applied to the filtered series that was turned into a frame. In the end
the op function is applied
let letsTransformAFilter = seq [(createFilter boolFunction seriesForFrameFloat)]
let op =fun (x:seq<float>) -> Seq.mean x
let aggregations = aggregate op dropAllKeyColumnsBut seriesForPropertyDropMod letsTransformAFilter seriesForFrameFloat
aggregations.Print()
assemble
takes a sequence of Series and creates a frame
let forKeySeriesOne:Series<_,int> = seq [(newKeyTest"Two" 1).addCol("T",2), 6;(newKeyTest"Two" 3).addCol("T",5), 9]|>series
let forKeySeriesTwo:Series<_,int> = seq [(newKeyTest"Two" 1).addCol("T",2), 6;(newKeyTest"Two" 3).addCol("T",5), 9]|>series
let assembly =
assemble
[
"One",forKeySeriesOne:>ISeries<Key>
"Two",forKeySeriesTwo:>ISeries<Key>
]
assembly.Print()
One Two
Two: 1
T: 2
-> 6 6
Two: 3
T: 5
-> 9 9
|
pivot
is a function that takes a string and a Frame. The string decides which row Key
is applied to the column key, the value part is applied.
The values in rows that were deleted are moved into the still existing rows
let testString ="One"
let testPivot = pivot testString seriesToFrameTestIndexed
testPivot.Print()
4.One 4.Two 4.Value 2.One 2.Two 2.Value
Two: 2
-> 4 2 1 <missing> <missing> <missing>
Two: 5
-> <missing> <missing> <missing> 2 5 2
|
NumericAggregation
does either the mean, median or float based on your input. For that it needs a Frame
of <Key,_>
a fliter, a <seq <Series <Key,bool>>>
or a <seq <seq <Series <Key,bool>>>>
, that say which values should be aggregated and for a singel column a string
The module has two functions either numAgAllCol
that aggregates over all columns or numAggregat
that agggregates one column
The result is a Frame
NumericFilter
is a module that can say if values in a given column are bigger or smaller than a given value.
The resultant series of the type <Key,bool>
.
The input Frame needs to be of the type Frame<Key,_>
.
The module has one function for all columns in a frame: numericFilterServeralCol
and one for a single columnnumericFilter
which also needs a string to determine the column
The NumericTransform
has five operations that can be done on all values in either a column(series) or a frame:
| Log2
| Subtract
| Add
| DivideBy
| MultiplyBy
These are can be either used on a full frame, numericTransformAllCols
, or on a single column, numericTransformOneCol
.
Both need a Frame of the type <Key,_>
and a seq, to determine which columns are dropped but numericTransform
needs a string to determine the column.
The GroupWiseNumericTransform
has four operations:
| DivideByMedian
| DivideByMean
| SubtractMedian
| SubtractMean
These are can be either used on a full frame,groupWiseNumericTransformAllCols
, or on a single column, groupWiseNumericTransform
.
Both need a Frame of the type <Key,_>
and a seq, to determine which columns are dropped but groupWiseNumericTransform
needs a string to determine the column.
Groupfilter
filters the given Frame of <Key,_>
. If a value of a Series (column), is either a bigger or lower than the given Tukey or stdev of the series than the bool is otherwise it is
The end result is a Series of Key true/false pairs or a seq of series <Key,bool>
for the variant that iterates over the entire frame.
groupFilter
only uses one column of a Frame and groupFilterAllCol
iterats over the entire frame
StrinAggregation concatenates string in the provide Series of <Key,string>
.
This happens based on the filter provided.
stAggregate
only uses one column of a Frame and stAggregateFullFrame
iterates over the entire frame
namespace Deedle
Multiple items
namespace FSharp
--------------------
namespace Microsoft.FSharp
namespace FSharp.Stats
namespace FSharpAux
namespace Drafo
module Core
from Drafo
val newKeyTest: str: string -> a: 'a -> Key
val str: string
val a: 'a
Multiple items
type Key =
inherit DynamicObj
new: unit -> Key
override Equals: b: obj -> bool
override GetHashCode: unit -> int
override ToString: unit -> string
member addCol: columns: (string * 'a) -> Key
--------------------
new: unit -> Key
val seriesForFrame: Series<Key,float>
Multiple items
module Series
from Deedle
--------------------
type Series =
static member ofNullables: values: seq<Nullable<'a0>> -> Series<int,'a0> (requires default constructor and value type and 'a0 :> ValueType)
static member ofObservations: observations: seq<'c * 'd> -> Series<'c,'d> (requires equality)
static member ofOptionalObservations: observations: seq<'K * 'a1 option> -> Series<'K,'a1> (requires equality)
static member ofValues: values: seq<'a> -> Series<int,'a>
--------------------
type Series<'K,'V (requires equality)> =
interface IFsiFormattable
interface ISeries<'K>
new: index: IIndex<'K> * vector: IVector<'V> * vectorBuilder: IVectorBuilder * indexBuilder: IIndexBuilder -> Series<'K,'V> + 3 overloads
member After: lowerExclusive: 'K -> Series<'K,'V>
member Aggregate: aggregation: Aggregation<'K> * keySelector: Func<DataSegment<Series<'K,'V>>,'TNewKey> * valueSelector: Func<DataSegment<Series<'K,'V>>,OptionalValue<'R>> -> Series<'TNewKey,'R> (requires equality) + 1 overload
member AsyncMaterialize: unit -> Async<Series<'K,'V>>
member Before: upperExclusive: 'K -> Series<'K,'V>
member Between: lowerInclusive: 'K * upperInclusive: 'K -> Series<'K,'V>
member Compare: another: Series<'K,'V> -> Series<'K,Diff<'V>>
member Convert: forward: Func<'V,'R> * backward: Func<'R,'V> -> Series<'K,'R>
...
--------------------
new: pairs: seq<System.Collections.Generic.KeyValuePair<'K,'V>> -> Series<'K,'V>
new: keys: seq<'K> * values: seq<'V> -> Series<'K,'V>
new: keys: 'K[] * values: 'V[] -> Series<'K,'V>
new: index: Indices.IIndex<'K> * vector: IVector<'V> * vectorBuilder: Vectors.IVectorBuilder * indexBuilder: Indices.IIndexBuilder -> Series<'K,'V>
val series: observations: seq<'a * 'b> -> Series<'a,'b> (requires equality)
val seriesToFrameTest: Frame<int,string>
val seriesToFrame: s: Series<Key,'a> -> Frame<int,string>
static member FrameExtensions.Print: frame: Frame<'K,'V> -> unit (requires equality and equality)
static member FrameExtensions.Print: frame: Frame<'K,'V> * printTypes: bool -> unit (requires equality and equality)
val seriesToFrameTestIndexed: Frame<Key,string>
val indexWithColumnValues: keyCols: seq<string> -> f: Frame<'a,string> -> Frame<Key,string> (requires equality)
val getColumn2: Series<Key,string>
Multiple items
val string: value: 'T -> string
<summary>Converts the argument to a string using <c>ToString</c>.</summary>
<remarks>For standard integer and floating point values the and any type that implements <c>IFormattable</c><c>ToString</c> conversion uses <c>CultureInfo.InvariantCulture</c>. </remarks>
<param name="value">The input value.</param>
<returns>The converted string.</returns>
<example id="string-example"><code lang="fsharp"></code></example>
--------------------
type string = System.String
<summary>An abbreviation for the CLI type <see cref="T:System.String" />.</summary>
<category>Basic Types</category>
val getColumn: column: string -> f: Frame<Key,string> -> Series<Key,'a>
static member SeriesExtensions.Print: series: Series<'K,'V> -> unit (requires equality)
val exmpColMajorFrameTwo: Frame<Key,string>
val frame: columns: seq<'a * #ISeries<'c>> -> Frame<'c,'a> (requires equality and equality)
val testRowToColumnKey: Frame<int,string>
val rowKeyToColumns: f: Frame<Key,string> -> Frame<int,string>
val boolFunction: a: float -> bool
val a: float
val letsCreateAFilter: Series<Key,bool>
val createFilter: op: ('a -> bool) -> s: Series<'KeyType,'a> -> Series<'KeyType,bool> (requires equality)
val transformFuction: a: float -> float
val letsTransformSomeSeries: Series<Key,float>
val transform: op: ('a -> 'b) -> s: Series<'KeyType,'a> -> Series<'KeyType,'b> (requires equality)
val getColumnOne: Series<Key,float>
Multiple items
val float: value: 'T -> float (requires member op_Explicit)
<summary>Converts the argument to 64-bit float. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using <c>Double.Parse()</c>
with InvariantCulture settings. Otherwise the operation requires an appropriate
static conversion method on the input type.</summary>
<param name="value">The input value.</param>
<returns>The converted float</returns>
<example id="float-example"><code lang="fsharp"></code></example>
--------------------
[<Struct>]
type float = System.Double
<summary>An abbreviation for the CLI type <see cref="T:System.Double" />.</summary>
<category>Basic Types</category>
--------------------
type float<'Measure> =
float
<summary>The type of double-precision floating point numbers, annotated with a unit of measure.
The unit of measure is erased in compiled code and when values of this type
are analyzed using reflection. The type is representationally equivalent to
<see cref="T:System.Double" />.</summary>
<category index="6">Basic Types with Units of Measure</category>
val getColumnTwo: Series<Key,float>
val zipped: Series<Key,float>
val zip: op: ('a -> 'a -> 'b) -> s1: Series<'KeyType,'a> -> s2: Series<'KeyType,'a> -> Series<'KeyType,'b> (requires equality)
val x: float
val y: float
val seriesForPropertyDrop: seq<string>
Multiple items
val seq: sequence: seq<'T> -> seq<'T>
<summary>Builds a sequence using sequence expression syntax</summary>
<param name="sequence">The input sequence.</param>
<returns>The result sequence.</returns>
<example id="seq-cast-example"><code lang="fsharp">
seq { for i in 0..10 do yield (i, i*i) }
</code></example>
--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>
<summary>An abbreviation for the CLI type <see cref="T:System.Collections.Generic.IEnumerable`1" /></summary>
<remarks>
See the <see cref="T:Microsoft.FSharp.Collections.SeqModule" /> module for further operations related to sequences.
See also <a href="https://docs.microsoft.com/dotnet/fsharp/language-reference/sequences">F# Language Guide - Sequences</a>.
</remarks>
val keyForPropertyDrop: Key
val dropsProperty: Key
val dropKeyColumns: keyColumns: seq<string> -> key: Key -> Key
val dropsAllPropBut: Key
val dropAllKeyColumnsBut: keyColumns: seq<string> -> key: Key -> Key
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
<summary>Print to <c>stdout</c> using the given format, and add a newline.</summary>
<param name="format">The formatter.</param>
<returns>The formatted result.</returns>
<example>See <c>Printf.printfn</c> (link: <see cref="M:Microsoft.FSharp.Core.PrintfModule.PrintFormatLine``1" />) for examples.</example>
val seriesForFrameFloat: Series<Key,float>
val seriesForPropertyDropMod: seq<string>
val operation: x: seq<float> -> (float -> float)
val x: seq<float>
val m: float
Multiple items
module Seq
from FSharpAux
--------------------
module Seq
from FSharp.Stats
<summary>
Module to compute common statistical measure
</summary>
--------------------
module Seq
from Microsoft.FSharp.Collections
<summary>Contains operations for working with values of type <see cref="T:Microsoft.FSharp.Collections.seq`1" />.</summary>
val mean: items: seq<'T> -> 'U (requires member (+) and member get_Zero and member DivideByInt and member (/))
<summary>
Computes the population mean (Normalized by N)
</summary>
<param name="items">The input sequence.</param>
<remarks>Returns default value if data is empty or if any entry is NaN.</remarks>
<returns>population mean (Normalized by N)</returns>
val tryGroupsTransform: Series<Key,float>
val groupTransform: op: ('a[] -> 'a -> 'b) -> modifyKeyColumns: (seq<string> -> 'KeyType -> 'a0) -> keyColumns: seq<string> -> s: Series<'KeyType,'a> -> Series<'KeyType,'b> (requires equality and equality)
val opFilter: values: seq<float> -> (float -> bool)
val values: seq<float>
val mean: float
val values: float
val tryGroupsFilter: Series<Key,bool>
val createGroupFilter: op: ('a[] -> 'a -> bool) -> modifyKeyColumns: (seq<string> -> 'KeyType -> 'a0) -> keyColumns: seq<string> -> s: Series<'KeyType,'a> -> Series<'KeyType,bool> (requires equality and equality)
val letsTransformAFilter: seq<Series<Key,bool>>
val op: x: seq<float> -> float
val aggregations: Series<Key,float>
val aggregate: op: (seq<'A> -> 'C) -> modifyKeyColumns: (seq<string> -> Key -> Key) -> keyColumns: seq<string> -> filters: seq<Series<Key,bool>> -> col: Series<Key,'A> -> Series<Key,'C>
val forKeySeriesOne: Series<Key,int>
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
<summary>Converts the argument to signed 32-bit integer. This is a direct conversion for all
primitive numeric types. For strings, the input is converted using <c>Int32.Parse()</c>
with InvariantCulture settings. Otherwise the operation requires an appropriate
static conversion method on the input type.</summary>
<param name="value">The input value.</param>
<returns>The converted int</returns>
<example id="int-example"><code lang="fsharp"></code></example>
--------------------
[<Struct>]
type int = int32
<summary>An abbreviation for the CLI type <see cref="T:System.Int32" />.</summary>
<category>Basic Types</category>
--------------------
type int<'Measure> =
int
<summary>The type of 32-bit signed integer numbers, annotated with a unit of measure. The unit
of measure is erased in compiled code and when values of this type
are analyzed using reflection. The type is representationally equivalent to
<see cref="T:System.Int32" />.</summary>
<category>Basic Types with Units of Measure</category>
val forKeySeriesTwo: Series<Key,int>
val assembly: Frame<Key,string>
val assemble: cols: seq<string * #ISeries<Key>> -> Frame<Key,string>
type ISeries<'K (requires equality)> =
abstract TryGetObject: 'K -> OptionalValue<obj>
abstract Index: IIndex<'K>
abstract Vector: IVector
abstract VectorBuilder: IVectorBuilder
val testString: string
val testPivot: Frame<Key,string>
val pivot: pivotCol: string -> assembeledFrame: Frame<Key,string> -> Frame<Key,string>