Deedle


SeriesExtensions

Namespace: Deedle
Attributes:
[<Extension>]

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
SeriesExtensions.SortByKey(series)
Signature: series:Series<'K,'T> -> Series<'K,'T>
Type parameters: 'K, 'T Attributes:
[<Extension>]

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
SeriesExtensions.ResampleEquivalence(...)
Signature: (series:Series<'K,'V> * keyProj:Func<'K,'?687707> * aggregate:Func<Series<'K,'V>,'?687708>) -> Series<'?687707,'?687708>
Type parameters: 'K, 'V, '?687707, '?687708 Attributes:
[<Extension>]

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.

SeriesExtensions.ResampleEquivalence(...)
Signature: (series:Series<'K,'V> * keyProj:Func<'K,'?687703>) -> Series<'?687703,Series<'K,'V>>
Type parameters: 'K, 'V, '?687703 Attributes:
[<Extension>]

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.

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

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.

SeriesExtensions.ResampleUniform(...)
Signature: (series:Series<'K,'V> * keyProj:Func<'K,'?687712> * nextKey:Func<'?687712,'?687712>) -> Series<'?687712,'V>
Type parameters: 'K, 'V, '?687712 Attributes:
[<Extension>]

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.

SeriesExtensions.Sample(...)
Signature: (series:Series<DateTimeOffset,'V> * interval:TimeSpan) -> Series<DateTimeOffset,'V>
Type parameters: 'V Attributes:
[<Extension>]

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.

SeriesExtensions.Sample(...)
Signature: (series:Series<DateTime,'V> * interval:TimeSpan) -> Series<DateTime,'V>
Type parameters: 'V Attributes:
[<Extension>]

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.

SeriesExtensions.Sample(...)
Signature: (series:Series<DateTimeOffset,'V> * interval:TimeSpan * dir:Direction) -> Series<DateTimeOffset,'V>
Type parameters: 'V Attributes:
[<Extension>]

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.

SeriesExtensions.Sample(...)
Signature: (series:Series<DateTime,'V> * interval:TimeSpan * dir:Direction) -> Series<DateTime,'V>
Type parameters: 'V Attributes:
[<Extension>]

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.

SeriesExtensions.Sample(...)
Signature: (series:Series<DateTimeOffset,'V> * start:DateTimeOffset * interval:TimeSpan * dir:Direction) -> Series<DateTimeOffset,'V>
Type parameters: 'V Attributes:
[<Extension>]

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.

SeriesExtensions.Sample(...)
Signature: (series:Series<DateTime,'V> * start:DateTime * interval:TimeSpan * dir:Direction) -> Series<DateTime,'V>
Type parameters: 'V Attributes:
[<Extension>]

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.

SeriesExtensions.Sample(series, keys)
Signature: (series:Series<'K,'V> * keys:seq<'K>) -> Series<'K,'V>
Type parameters: 'K, 'V Attributes:
[<Extension>]

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.

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

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.

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

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
SeriesExtensions.DropMissing(series)
Signature: series:Series<'K,'V> -> Series<'K,'V>
Type parameters: 'K, 'V Attributes:
[<Extension>]

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
val fsi : Compiler.Interactive.InteractiveSession
Multiple items
val int : value:'T -> int (requires member op_Explicit)

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

--------------------
type int<'Measure> = int
Multiple items
val float : value:'T -> float (requires member op_Explicit)

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

--------------------
type float<'Measure> = float
SeriesExtensions.FillMissing(...)
Signature: (series:Series<'K,'T> * filler:Func<'K,'T>) -> Series<'K,'T>
Type parameters: 'K, 'T Attributes:
[<Extension>]

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

SeriesExtensions.FillMissing(...)
Signature: (series:Series<'K,'T> * direction:Direction) -> Series<'K,'T>
Type parameters: 'K, 'T Attributes:
[<Extension>]

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
SeriesExtensions.FillMissing(...)
Signature: (series:Series<'K,'T> * value:'T) -> Series<'K,'T>
Type parameters: 'K, 'T Attributes:
[<Extension>]

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
SeriesExtensions.Chunk(series, size)
Signature: (series:Series<'K,'V> * size:int) -> Series<'K,Series<'K,'V>>
Type parameters: 'K, 'V Attributes:
[<Extension>]
SeriesExtensions.ChunkInto(...)
Signature: (series:Series<'K,'V> * size:int * reduce:Func<Series<'K,'V>,'U>) -> Series<'K,'U>
Type parameters: 'K, 'V, 'U Attributes:
[<Extension>]
SeriesExtensions.ChunkInto(...)
Signature: (series:Series<'K1,'V> * size:int * selector:Func<Series<'K1,'V>,KeyValuePair<'K2,'U>>) -> Series<'K2,'U>
Type parameters: 'K1, 'V, 'K2, 'U Attributes:
[<Extension>]
SeriesExtensions.ContainsKey(...)
Signature: (series:Series<'K,'T> * key:'K) -> bool
Type parameters: 'K, 'T Attributes:
[<Extension>]
SeriesExtensions.Diff(series, offset)
Signature: (series:Series<'K,int> * offset:int) -> Series<'K,int>
Type parameters: 'K Attributes:
[<Extension>]

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.
SeriesExtensions.Diff(series, offset)
Signature: (series:Series<'K,decimal> * offset:int) -> Series<'K,decimal>
Type parameters: 'K Attributes:
[<Extension>]

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.
SeriesExtensions.Diff(series, offset)
Signature: (series:Series<'K,float32> * offset:int) -> Series<'K,float32>
Type parameters: 'K Attributes:
[<Extension>]

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.
SeriesExtensions.Diff(series, offset)
Signature: (series:Series<'K,float> * offset:int) -> Series<'K,float>
Type parameters: 'K Attributes:
[<Extension>]

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.
SeriesExtensions.FillMissing(...)
Signature: (series:Series<'K,'T> * startKey:'K * endKey:'K * direction:Direction) -> Series<'K,'T>
Type parameters: 'K, 'T Attributes:
[<Extension>]
SeriesExtensions.FirstKey(series)
Signature: series:Series<'K,'V> -> 'K
Type parameters: 'K, 'V Attributes:
[<Extension>]
SeriesExtensions.FirstValue(series)
Signature: series:Series<'K,'V> -> 'V
Type parameters: 'K, 'V Attributes:
[<Extension>]
SeriesExtensions.Flatten(series)
Signature: (series:Series<'K,'T opt>) -> Series<'K,'T>
Type parameters: 'K, 'T Attributes:
[<Extension>]

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

SeriesExtensions.GetAllObservations(...)
Signature: series:Series<'K,'T> -> seq<KeyValuePair<'K,OptionalValue<'T>>>
Type parameters: 'K, 'T Attributes:
[<Extension>]

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.

SeriesExtensions.GetAllValues(series)
Signature: series:Series<'K,'T> -> seq<OptionalValue<'T>>
Type parameters: 'K, 'T Attributes:
[<Extension>]

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

SeriesExtensions.GetObservations(series)
Signature: series:Series<'K,'T> -> seq<KeyValuePair<'K,'T>>
Type parameters: 'K, 'T Attributes:
[<Extension>]

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.).

SeriesExtensions.GetSlice(...)
Signature: (series:Series<('K1 * 'K2),'V> * k1:'K1 * lo2:'K2 option * hi2:'K2 option) -> Series<('K1 * 'K2),'V>
Type parameters: 'K1, 'K2, 'V Attributes:
[<Extension>]
[<EditorBrowsable(1)>]
SeriesExtensions.GetSlice(...)
Signature: (series:Series<('K1 * 'K2),'V> * lo1:'K1 option * hi1:'K1 option * k2:'K2) -> Series<('K1 * 'K2),'V>
Type parameters: 'K1, 'K2, 'V Attributes:
[<Extension>]
[<EditorBrowsable(1)>]
SeriesExtensions.GetSlice(...)
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 Attributes:
[<Extension>]
[<EditorBrowsable(1)>]
SeriesExtensions.LastKey(series)
Signature: series:Series<'K,'V> -> 'K
Type parameters: 'K, 'V Attributes:
[<Extension>]
SeriesExtensions.LastValue(series)
Signature: series:Series<'K,'V> -> 'V
Type parameters: 'K, 'V Attributes:
[<Extension>]
SeriesExtensions.Log(series)
Signature: series:Series<'K,float> -> Series<'K,float>
Type parameters: 'K Attributes:
[<Extension>]
SeriesExtensions.OrderByKey(series)
Signature: series:Series<'K,'T> -> Series<'K,'T>
Type parameters: 'K, 'T Attributes:
[<Extension>]
[<Obsolete("Use SortByKeys instead. This function will be removed in futrue versions.")>]
WARNING: This API is obsolete

Use SortByKeys instead. This function will be removed in futrue versions.

SeriesExtensions.Print(series)
Signature: series:Series<'K,'V> -> unit
Type parameters: 'K, 'V Attributes:
[<Extension>]
SeriesExtensions.Shift(series, offset)
Signature: (series:Series<'K,'V> * offset:int) -> Series<'K,'V>
Type parameters: 'K, 'V Attributes:
[<Extension>]

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.

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