Deedle


SeriesExtensions

Namespace: Deedle

The type implements C# and F# extension methods for the Series<'K, 'V> type. The members are automatically available when you import the Deedle namespace. The type contains object-oriented counterparts to most of the functionality from the Series module.

Table of contents

Data structure manipulation 

Static members

Static memberDescription
SortByKey(series)
Signature: series:Series<'K,'T> -> Series<'K,'T>
Type parameters: 'K, 'T

Returns a new series whose entries are reordered according to index order

Parameters

  • series - An input series to be used

Lookup, resampling and scaling 

Static members

Static memberDescription
ResampleEquivalence(...)
Signature: (series:Series<'K,'V> * keyProj:Func<'K,'?492666> * aggregate:Func<Series<'K,'V>,'?492667>) -> Series<'?492666,'?492667>
Type parameters: 'K, 'V, '?492666, '?492667

Resample the series based on equivalence class on the keys. A specified function keyProj is used to project keys to another space and the observations for which the projected keys are equivalent are grouped into chunks. The chunks are then transformed to values using the provided function f.

Parameters

  • series - An input series to be resampled
  • keyProj - A function that transforms keys from original space to a new space (which is then used for grouping based on equivalence)
  • aggregate - A function that is used to collapse a generated chunk into a single value.

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered. For unordered series, similar functionality can be implemented using GroupBy.

ResampleEquivalence(series, keyProj)
Signature: (series:Series<'K,'V> * keyProj:Func<'K,'?492662>) -> Series<'?492662,Series<'K,'V>>
Type parameters: 'K, 'V, '?492662

Resample the series based on equivalence class on the keys. A specified function keyProj is used to project keys to another space and the observations for which the projected keys are equivalent are grouped into chunks. The chunks are then returned as nested series.

Parameters

  • series - An input series to be resampled
  • keyProj - A function that transforms keys from original space to a new space (which is then used for grouping based on equivalence)

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered. For unordered series, similar functionality can be implemented using GroupBy.

ResampleUniform(...)
Signature: (series:Series<'K1,'V> * keyProj:Func<'K1,'K2> * nextKey:Func<'K2,'K2> * fillMode:Lookup) -> Series<'K2,'V>
Type parameters: 'K1, 'V, 'K2

Resample the series based on equivalence class on the keys and also generate values for all keys of the target space that are between the minimal and maximal key of the specified series (e.g. generate value for all days in the range covered by the series). A specified function keyProj is used to project keys to another space and nextKey is used to generate all keys in the range. The last value of each chunk is returned.

When there are no values for a (generated) key, then the function attempts to get the greatest value from the previous smaller chunk (i.e. value for the previous date time).

Parameters

  • series - An input series to be resampled
  • fillMode - When set to Lookup.NearestSmaller or Lookup.NearestGreater, the function searches for a nearest available observation in an neighboring chunk. Otherwise, the function f is called with an empty series as an argument.
  • keyProj - A function that transforms keys from original space to a new space (which is then used for grouping based on equivalence)
  • nextKey - A function that gets the next key in the transformed space

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered.

ResampleUniform(...)
Signature: (series:Series<'K,'V> * keyProj:Func<'K,'?492671> * nextKey:Func<'?492671,'?492671>) -> Series<'?492671,'V>
Type parameters: 'K, 'V, '?492671

Resample the series based on equivalence class on the keys and also generate values for all keys of the target space that are between the minimal and maximal key of the specified series (e.g. generate value for all days in the range covered by the series). For each equivalence class (e.g. date), select the latest value (with greatest key). A specified function keyProj is used to project keys to another space and nextKey is used to generate all keys in the range.

When there are no values for a (generated) key, then the function attempts to get the greatest value from the previous smaller chunk (i.e. value for the previous date time).

Parameters

  • series - An input series to be resampled
  • keyProj - A function that transforms keys from original space to a new space (which is then used for grouping based on equivalence)
  • nextKey - A function that gets the next key in the transformed space

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered.

Sample(series, interval)
Signature: (series:Series<DateTimeOffset,'V> * interval:TimeSpan) -> Series<DateTimeOffset,'V>
Type parameters: 'V

Finds values at, or near, the specified times in a given series. The operation generates keys starting from the smallest key of the original series, using the specified interval and then finds nearest smaller values close to such keys. The function generates samples at, or just before the end of an interval and at, or after, the end of the series.

Parameters

  • series - An input series to be resampled
  • interval - The interval between the individual samples

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered.

Sample(series, interval)
Signature: (series:Series<DateTime,'V> * interval:TimeSpan) -> Series<DateTime,'V>
Type parameters: 'V

Finds values at, or near, the specified times in a given series. The operation generates keys starting from the smallest key of the original series, using the specified interval and then finds nearest smaller values close to such keys. The function generates samples at, or just before the end of an interval and at, or after, the end of the series.

Parameters

  • series - An input series to be resampled
  • interval - The interval between the individual samples

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered.

Sample(series, interval, dir)
Signature: (series:Series<DateTimeOffset,'V> * interval:TimeSpan * dir:Direction) -> Series<DateTimeOffset,'V>
Type parameters: 'V

Finds values at, or near, the specified times in a given series. The operation generates keys starting from the smallest key of the original series, using the specified interval and then finds nearest smaller values close to such keys according to dir.

Parameters

  • series - An input series to be resampled
  • interval - The interval between the individual samples
  • dir - Specifies how the keys should be generated. Direction.Forward means that the key is the smallest value of each chunk (and so first key of the series is returned and the last is not, unless it matches exactly start + k*interval); Direction.Backward means that the first key is skipped and sample is generated at, or just before the end of interval and at the end of the series.

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered.

Sample(series, interval, dir)
Signature: (series:Series<DateTime,'V> * interval:TimeSpan * dir:Direction) -> Series<DateTime,'V>
Type parameters: 'V

Finds values at, or near, the specified times in a given series. The operation generates keys starting from the smallest key of the original series, using the specified interval and then finds nearest smaller values close to such keys according to dir.

Parameters

  • series - An input series to be resampled
  • interval - The interval between the individual samples
  • lookup - Specifies how the lookup based on keys is performed. Exact means that the values at exact keys will be returned; NearestGreater returns the nearest greater key value (starting at the first key) and NearestSmaller returns the nearest smaller key value (starting at most interval after the end of the series)

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered.

Sample(series, start, interval, dir)
Signature: (series:Series<DateTimeOffset,'V> * start:DateTimeOffset * interval:TimeSpan * dir:Direction) -> Series<DateTimeOffset,'V>
Type parameters: 'V

Finds values at, or near, the specified times in a given series. The operation generates keys starting at the specified start time, using the specified interval and then finds nearest smaller values close to such keys according to dir.

Parameters

  • series - An input series to be resampled
  • start - The initial time to be used for sampling
  • interval - The interval between the individual samples
  • lookup - Specifies how the lookup based on keys is performed. Exact means that the values at exact keys will be returned; NearestGreater returns the nearest greater key value (starting at the first key) and NearestSmaller returns the nearest smaller key value (starting at most interval after the end of the series)

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered.

Sample(series, start, interval, dir)
Signature: (series:Series<DateTime,'V> * start:DateTime * interval:TimeSpan * dir:Direction) -> Series<DateTime,'V>
Type parameters: 'V

Finds values at, or near, the specified times in a given series. The operation generates keys starting at the specified start time, using the specified interval and then finds nearest smaller values close to such keys according to dir.

Parameters

  • series - An input series to be resampled
  • start - The initial time to be used for sampling
  • interval - The interval between the individual samples
  • lookup - Specifies how the lookup based on keys is performed. Exact means that the values at exact keys will be returned; NearestGreater returns the nearest greater key value (starting at the first key) and NearestSmaller returns the nearest smaller key value (starting at most interval after the end of the series)

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered.

Sample(series, keys)
Signature: (series:Series<'K,'V> * keys:seq<'K>) -> Series<'K,'V>
Type parameters: 'K, 'V

Sample an (ordered) series by finding the value at the exact or closest prior key for some new sequence of keys.

Parameters

  • series - An input series to be sampled
  • keys - The keys at which to sample

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered.

SampleInto(...)
Signature: (series:Series<DateTimeOffset,'V> * interval:TimeSpan * dir:Direction * aggregate:Func<DateTimeOffset,(Series<DateTimeOffset,'V> -> obj)>) -> Series<DateTimeOffset,obj>
Type parameters: 'V

Performs sampling by time and aggregates chunks obtained by time-sampling into a single value using a specified function. The operation generates keys starting at the first key in the source series, using the specified interval and then obtains chunks based on these keys in a fashion similar to the Series.resample function.

Parameters

  • series - An input series to be resampled
  • interval - The interval between the individual samples
  • dir - If this parameter is Direction.Forward, then each key is used as the smallest key in a chunk; for Direction.Backward, the keys are used as the greatest keys in a chunk.
  • aggregate - A function that is called to aggregate each chunk into a single value.

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered.

SampleInto(...)
Signature: (series:Series<DateTime,'V> * interval:TimeSpan * dir:Direction * aggregate:Func<DateTime,(Series<DateTime,'V> -> obj)>) -> Series<DateTime,obj>
Type parameters: 'V

Performs sampling by time and aggregates chunks obtained by time-sampling into a single value using a specified function. The operation generates keys starting at the first key in the source series, using the specified interval and then obtains chunks based on these keys in a fashion similar to the Series.resample function.

Parameters

  • series - An input series to be resampled
  • interval - The interval between the individual samples
  • dir - If this parameter is Direction.Forward, then each key is used as the smallest key in a chunk; for Direction.Backward, the keys are used as the greatest keys in a chunk.
  • aggregate - A function that is called to aggregate each chunk into a single value.

Remarks

This operation is only supported on ordered series. The method throws InvalidOperationException when the series is not ordered.

Missing values 

Static members

Static memberDescription
DropMissing(series)
Signature: series:Series<'K,'V> -> Series<'K,'V>
Type parameters: 'K, 'V

Drop missing values from the specified series. The returned series contains only those keys for which there is a value available in the original one.

Parameters

  • series - An input series to be filtered

Example

1: 
2: 
3: 
let s = series [ 1 => 1.0; 2 => Double.NaN ]
s.DropMissing()
[fsi:val it : Series<int,float> = series [ 1 => 1]
val s : obj

Full name: docs.s
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
Multiple items
val float : value:'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------
type float = System.Double

Full name: Microsoft.FSharp.Core.float

--------------------
type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>
FillMissing(series, filler)
Signature: (series:Series<'K,'T> * filler:Func<'K,'T>) -> Series<'K,'T>
Type parameters: 'K, 'T

Fill missing values in the series using the specified function. The specified function is called with all keys for which the series does not contain value and the result of the call is used in place of the missing value.

Parameters

  • series - An input series that is to be filled
  • filler - A function that takes key K and generates a value to be used in a place where the original series contains a missing value.

Remarks

This function can be used to implement more complex interpolation. For example see handling missing values in the tutorial

FillMissing(series, direction)
Signature: (series:Series<'K,'T> * direction:Direction) -> Series<'K,'T>
Type parameters: 'K, 'T

Fill missing values in the series with the nearest available value (using the specified direction). The default direction is Direction.Backward. Note that the series may still contain missing values after call to this function. This operation can only be used on ordered series.

Example

1: 
2: 
3: 
4: 
5: 
6: 
7: 
let sample = Series.ofValues [ Double.NaN; 1.0; Double.NaN; 3.0 ]

// Returns a series consisting of [1; 1; 3; 3]
sample.FillMissing(Direction.Backward)

// Returns a series consisting of [<missing>; 1; 1; 3]
sample.FillMissing(Direction.Forward)

Parameters

  • direction - Specifies the direction used when searching for the nearest available value. Backward means that we want to look for the first value with a smaller key while Forward searches for the nearest greater key.
val sample : obj

Full name: docs.sample
FillMissing(series, value)
Signature: (series:Series<'K,'T> * value:'T) -> Series<'K,'T>
Type parameters: 'K, 'T

Fill missing values in the series with a constant value.

Parameters

  • series - An input series that is to be filled
  • value - A constant value that is used to fill all missing values

Other type members 

Static members

Static memberDescription
Chunk(series, size)
Signature: (series:Series<'K,'V> * size:int) -> Series<'K,Series<'K,'V>>
Type parameters: 'K, 'V
ChunkInto(series, size, reduce)
Signature: (series:Series<'K,'V> * size:int * reduce:Func<Series<'K,'V>,'U>) -> Series<'K,'U>
Type parameters: 'K, 'V, 'U
ChunkInto(series, size, selector)
Signature: (series:Series<'K1,'V> * size:int * selector:Func<Series<'K1,'V>,KeyValuePair<'K2,'U>>) -> Series<'K2,'U>
Type parameters: 'K1, 'V, 'K2, 'U
ContainsKey(series, key)
Signature: (series:Series<'K,'T> * key:'K) -> bool
Type parameters: 'K, 'T
Diff(series, offset)
Signature: (series:Series<'K,int> * offset:int) -> Series<'K,int>
Type parameters: 'K

Returns a series containing difference between a value in the original series and a value at the specified offset. For example, calling Series.diff 1 s returns a series where previous value is subtracted from the current one.

Parameters

  • offset - When positive, subtracts the past values from the current values; when negative, subtracts the future values from the current values.
  • series - The input series.
Diff(series, offset)
Signature: (series:Series<'K,decimal> * offset:int) -> Series<'K,decimal>
Type parameters: 'K

Returns a series containing difference between a value in the original series and a value at the specified offset. For example, calling Series.diff 1 s returns a series where previous value is subtracted from the current one.

Parameters

  • offset - When positive, subtracts the past values from the current values; when negative, subtracts the future values from the current values.
  • series - The input series.
Diff(series, offset)
Signature: (series:Series<'K,float32> * offset:int) -> Series<'K,float32>
Type parameters: 'K

Returns a series containing difference between a value in the original series and a value at the specified offset. For example, calling Series.diff 1 s returns a series where previous value is subtracted from the current one.

Parameters

  • offset - When positive, subtracts the past values from the current values; when negative, subtracts the future values from the current values.
  • series - The input series.
Diff(series, offset)
Signature: (series:Series<'K,float> * offset:int) -> Series<'K,float>
Type parameters: 'K

Returns a series containing difference between a value in the original series and a value at the specified offset. For example, calling Series.diff 1 s returns a series where previous value is subtracted from the current one.

Parameters

  • offset - When positive, subtracts the past values from the current values; when negative, subtracts the future values from the current values.
  • series - The input series.
FillMissing(...)
Signature: (series:Series<'K,'T> * startKey:'K * endKey:'K * direction:Direction) -> Series<'K,'T>
Type parameters: 'K, 'T
FirstKey(series)
Signature: series:Series<'K,'V> -> 'K
Type parameters: 'K, 'V
FirstValue(series)
Signature: series:Series<'K,'V> -> 'V
Type parameters: 'K, 'V
Flatten(series)
Signature: (series:Series<'K,'T opt>) -> Series<'K,'T>
Type parameters: 'K, 'T

Collapses a series of OptionalValue<'T> values to just 'T values

GetAllObservations(series)
Signature: series:Series<'K,'T> -> seq<KeyValuePair<'K,OptionalValue<'T>>>
Type parameters: 'K, 'T

Returns all keys from the sequence, together with the associated (optional) values. The values are returned using the OptionalValue<T> struct which provides HasValue for testing if the value is available.

GetAllValues(series)
Signature: series:Series<'K,'T> -> seq<OptionalValue<'T>>
Type parameters: 'K, 'T

Returns all (optional) values. The values are returned using the OptionalValue<T> struct which provides HasValue for testing if the value is available.

GetObservations(series)
Signature: series:Series<'K,'T> -> seq<KeyValuePair<'K,'T>>
Type parameters: 'K, 'T

Return observations with available values. The operation skips over all keys with missing values (such as values created from null, Double.NaN, or those that are missing due to outer join etc.).

GetSlice(series, k1, lo2, hi2)
Signature: (series:Series<('K1 * 'K2),'V> * k1:'K1 * lo2:'K2 option * hi2:'K2 option) -> Series<('K1 * 'K2),'V>
Type parameters: 'K1, 'K2, 'V
GetSlice(series, lo1, hi1, k2)
Signature: (series:Series<('K1 * 'K2),'V> * lo1:'K1 option * hi1:'K1 option * k2:'K2) -> Series<('K1 * 'K2),'V>
Type parameters: 'K1, 'K2, 'V
GetSlice(series, lo1, hi1, lo2, hi2)
Signature: (series:Series<('K1 * 'K2),'V> * lo1:'K1 option * hi1:'K1 option * lo2:'K2 option * hi2:'K2 option) -> Series<('K1 * 'K2),'V>
Type parameters: 'K1, 'K2, 'V
LastKey(series)
Signature: series:Series<'K,'V> -> 'K
Type parameters: 'K, 'V
LastValue(series)
Signature: series:Series<'K,'V> -> 'V
Type parameters: 'K, 'V
Log(series)
Signature: series:Series<'K,float> -> Series<'K,float>
Type parameters: 'K
OrderByKey(series)
Signature: series:Series<'K,'T> -> Series<'K,'T>
Type parameters: 'K, 'T
Print(series)
Signature: series:Series<'K,'V> -> unit
Type parameters: 'K, 'V
Shift(series, offset)
Signature: (series:Series<'K,'V> * offset:int) -> Series<'K,'V>
Type parameters: 'K, 'V

Returns a series with values shifted by the specified offset. When the offset is positive, the values are shifted forward and first offset keys are dropped. When the offset is negative, the values are shifted backwards and the last offset keys are dropped. Expressed in pseudo-code:

1: 
result[k] = series[k - offset]

Parameters

  • offset - Can be both positive and negative number.
  • series - The input series to be shifted.

Remarks

If you want to calculate the difference, e.g. s - (Series.shift 1 s), you can use Series.diff which will be a little bit faster.

Sort(series)
Signature: series:Series<'K,'V> -> Series<'K,'V>
Type parameters: 'K, 'V
SortBy(series, f)
Signature: (series:Series<'K,'V> * f:Func<'V,'V2>) -> Series<'K,'V>
Type parameters: 'K, 'V, 'V2
SortWith(series, cmp)
Signature: (series:Series<'K,'V> * cmp:Comparer<'V>) -> Series<'K,'V>
Type parameters: 'K, 'V
TryFirstValue(series)
Signature: series:Series<'K,'V> -> 'V option
Type parameters: 'K, 'V
TryLastValue(series)
Signature: series:Series<'K,'V> -> 'V option
Type parameters: 'K, 'V
Window(series, size)
Signature: (series:Series<'K,'V> * size:int) -> Series<'K,Series<'K,'V>>
Type parameters: 'K, 'V
WindowInto(series, size, reduce)
Signature: (series:Series<'K,'V> * size:int * reduce:Func<Series<'K,'V>,'U>) -> Series<'K,'U>
Type parameters: 'K, 'V, 'U
WindowInto(series, size, selector)
Signature: (series:Series<'K1,'V> * size:int * selector:Func<Series<'K1,'V>,KeyValuePair<'K2,'U>>) -> Series<'K2,'U>
Type parameters: 'K1, 'V, 'K2, 'U
Fork me on GitHub