DataSeries - Maple Help

Overview of DataSeries

Description

 • A DataSeries is a one-dimensional data container, similar to a one-dimensional Array, but whose entries can be referenced by "labels", as well as by position.
 • A related two-dimensional data container, known as a DataFrame is also available.

Indexing

 • You can access the elements of a DataSeries similar to the way in which you access Array elements, by indexing the DataSeries by position. If ds is a DataSeries, then ds[ i ] evaluates to the ith element of ds. However, the elements of a DataSeries are also associated with symbolic names, and you can use these names to refer to DataSeries elements as well.
 > ds := DataSeries( [ sin( x ), cos( x ), tan( x ) ], 'labels' = [ 's', 'c', 't' ] );
 ${\mathrm{ds}}{≔}\left[\begin{array}{cc}{s}& {\mathrm{sin}}{}\left({x}\right)\\ {c}& {\mathrm{cos}}{}\left({x}\right)\\ {t}& {\mathrm{tan}}{}\left({x}\right)\end{array}\right]$ (1)
 > ds[ 2 ];
 ${\mathrm{cos}}{}\left({x}\right)$ (2)
 > ds[ 'c' ];
 ${\mathrm{cos}}{}\left({x}\right)$ (3)
 • To select a range of entries in a DataSeries, returning the result as a DataSeries, use a range of indices or labels.
 > ds[ 1 .. 2 ];
 $\left[\begin{array}{cc}{s}& {\mathrm{sin}}{}\left({x}\right)\\ {c}& {\mathrm{cos}}{}\left({x}\right)\end{array}\right]$ (4)
 > ds[ 'c' .. 't' ];
 $\left[\begin{array}{cc}{c}& {\mathrm{cos}}{}\left({x}\right)\\ {t}& {\mathrm{tan}}{}\left({x}\right)\end{array}\right]$ (5)
 • Note that indices and labels can be used together:
 > ds[ 'c' .. -1 ];
 $\left[\begin{array}{cc}{c}& {\mathrm{cos}}{}\left({x}\right)\\ {t}& {\mathrm{tan}}{}\left({x}\right)\end{array}\right]$ (6)
 • You can select non-contiguous entries by enclosing the desired indices in a list.
 > ds[ [ 's', 't' ] ];
 $\left[\begin{array}{cc}{s}& {\mathrm{sin}}{}\left({x}\right)\\ {t}& {\mathrm{tan}}{}\left({x}\right)\end{array}\right]$ (7)
 • One particular application for this kind of index is to re-order the given DataSeries.
 > ds2 := ds[ [ 2, 3, 1 ] ];
 ${\mathrm{ds2}}{≔}\left[\begin{array}{cc}{c}& {\mathrm{cos}}{}\left({x}\right)\\ {t}& {\mathrm{tan}}{}\left({x}\right)\\ {s}& {\mathrm{sin}}{}\left({x}\right)\end{array}\right]$ (8)

Examples

 > $\mathrm{ds}≔\mathrm{DataSeries}\left(\left[4,5,6\right],'\mathrm{labels}'=\left['a','b','c'\right]\right)$
 ${\mathrm{ds}}{≔}\left[\begin{array}{cc}{a}& {4}\\ {b}& {5}\\ {c}& {6}\end{array}\right]$ (9)
 > $\mathrm{type}\left(\mathrm{ds},\mathrm{DataSeries}\right)$
 ${\mathrm{true}}$ (10)
 > $\mathrm{type}\left(\mathrm{ds},'\mathrm{Array}'\right)$
 ${\mathrm{false}}$ (11)
 > $\mathrm{ds}\left[1\right]$
 ${4}$ (12)
 > $\mathrm{ds}\left[b\right]$
 ${5}$ (13)
 > ds >~ 4;
 $\left[\begin{array}{cc}{a}& {\mathrm{false}}\\ {b}& {\mathrm{true}}\\ {c}& {\mathrm{true}}\end{array}\right]$ (14)
 > ds[ ds >~ 4 ];
 $\left[\begin{array}{cc}{b}& {5}\\ {c}& {6}\end{array}\right]$ (15)

Hourly temperatures reported by the BlackBerry Weather App for Waterloo, Ontario on October 27/28 2015.

 > $\mathrm{oct27_28}≔\mathrm{DataSeries}\left(\mathrm{map}\left(\mathrm{Temperature},\left[11,12,13,12,11,10,9,8,7,7,7,7,7,7,7,7,7,8,8,8,7,8,9,10\right],'\mathrm{degC}'\right),'\mathrm{labels}'=\left["12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00","20:00","21:00","22:00","23:00","00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08:00","09:00","10:00","11:00"\right]\right)$
 ${\mathrm{oct27_28}}{≔}\begin{array}{c}\left[\begin{array}{cc}{"12:00"}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{\mathrm{Temperature}}{}\left({11}{,}{\mathrm{Units}}{:-}{\mathrm{Unit}}{}\left({\mathrm{Celsius}}\right){,}{1}\right)\right]\right)\\ {"13:00"}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{\mathrm{Temperature}}{}\left({12}{,}{\mathrm{Units}}{:-}{\mathrm{Unit}}{}\left({\mathrm{Celsius}}\right){,}{1}\right)\right]\right)\\ {"14:00"}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{\mathrm{Temperature}}{}\left({13}{,}{\mathrm{Units}}{:-}{\mathrm{Unit}}{}\left({\mathrm{Celsius}}\right){,}{1}\right)\right]\right)\\ {"15:00"}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{\mathrm{Temperature}}{}\left({12}{,}{\mathrm{Units}}{:-}{\mathrm{Unit}}{}\left({\mathrm{Celsius}}\right){,}{1}\right)\right]\right)\\ {"16:00"}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{\mathrm{Temperature}}{}\left({11}{,}{\mathrm{Units}}{:-}{\mathrm{Unit}}{}\left({\mathrm{Celsius}}\right){,}{1}\right)\right]\right)\\ {"17:00"}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{\mathrm{Temperature}}{}\left({10}{,}{\mathrm{Units}}{:-}{\mathrm{Unit}}{}\left({\mathrm{Celsius}}\right){,}{1}\right)\right]\right)\\ {"18:00"}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{\mathrm{Temperature}}{}\left({9}{,}{\mathrm{Units}}{:-}{\mathrm{Unit}}{}\left({\mathrm{Celsius}}\right){,}{1}\right)\right]\right)\\ {"19:00"}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{\mathrm{Temperature}}{}\left({8}{,}{\mathrm{Units}}{:-}{\mathrm{Unit}}{}\left({\mathrm{Celsius}}\right){,}{1}\right)\right]\right)\\ {"20:00"}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{\mathrm{Temperature}}{}\left({7}{,}{\mathrm{Units}}{:-}{\mathrm{Unit}}{}\left({\mathrm{Celsius}}\right){,}{1}\right)\right]\right)\\ {"21:00"}& {\mathrm{Typesetting}}{:-}{\mathrm{_Hold}}{}\left(\left[{\mathrm{Temperature}}{}\left({7}{,}{\mathrm{Units}}{:-}{\mathrm{Unit}}{}\left({\mathrm{Celsius}}\right){,}{1}\right)\right]\right)\\ {⋮}& {⋮}\end{array}\right]\\ \hfill {\text{24 element DataSeries}}\end{array}$ (16)

Compute the average temperature over this 24-hour period.

 > $\mathrm{avg}≔\frac{\mathrm{add}\left(\mathrm{oct27_28}\right)}{\mathrm{numelems}\left(\mathrm{oct27_28}\right)}$
 ${\mathrm{avg}}{≔}\frac{{69}}{{8}}{}⟦{\mathrm{°C}}⟧$ (17)
 > $\mathrm{Value}\left(\mathrm{avg}\right)$
 $\frac{{69}}{{8}}$ (18)

DataSeries objects can be converted to an Array, Vector, Matrix, table, list, or set:

 > $\mathrm{convert}\left(\mathrm{oct27_28},'\mathrm{list}'\right)$
 $\left[{11}{}⟦{\mathrm{°C}}⟧{,}{12}{}⟦{\mathrm{°C}}⟧{,}{13}{}⟦{\mathrm{°C}}⟧{,}{12}{}⟦{\mathrm{°C}}⟧{,}{11}{}⟦{\mathrm{°C}}⟧{,}{10}{}⟦{\mathrm{°C}}⟧{,}{9}{}⟦{\mathrm{°C}}⟧{,}{8}{}⟦{\mathrm{°C}}⟧{,}{7}{}⟦{\mathrm{°C}}⟧{,}{7}{}⟦{\mathrm{°C}}⟧{,}{7}{}⟦{\mathrm{°C}}⟧{,}{7}{}⟦{\mathrm{°C}}⟧{,}{7}{}⟦{\mathrm{°C}}⟧{,}{7}{}⟦{\mathrm{°C}}⟧{,}{7}{}⟦{\mathrm{°C}}⟧{,}{7}{}⟦{\mathrm{°C}}⟧{,}{7}{}⟦{\mathrm{°C}}⟧{,}{8}{}⟦{\mathrm{°C}}⟧{,}{8}{}⟦{\mathrm{°C}}⟧{,}{8}{}⟦{\mathrm{°C}}⟧{,}{7}{}⟦{\mathrm{°C}}⟧{,}{8}{}⟦{\mathrm{°C}}⟧{,}{9}{}⟦{\mathrm{°C}}⟧{,}{10}{}⟦{\mathrm{°C}}⟧\right]$ (19)

Converting a DataSeries to a set only shows the unique elements:

 > $\mathrm{convert}\left(\mathrm{oct27_28},'\mathrm{set}'\right)$
 $\left\{{8}{}⟦{\mathrm{°C}}⟧{,}{7}{}⟦{\mathrm{°C}}⟧{,}{9}{}⟦{\mathrm{°C}}⟧{,}{10}{}⟦{\mathrm{°C}}⟧{,}{13}{}⟦{\mathrm{°C}}⟧{,}{12}{}⟦{\mathrm{°C}}⟧{,}{11}{}⟦{\mathrm{°C}}⟧\right\}$ (20)

Converting to a table is the only conversion that attempts to maintain information on labels:

 > $\mathrm{convert}\left(\mathrm{oct27_28},'\mathrm{table}'\right)$
 ${table}{}\left(\left[{"04:00"}{=}{7}{}⟦{\mathrm{°C}}⟧{,}{"14:00"}{=}{13}{}⟦{\mathrm{°C}}⟧{,}{"23:00"}{=}{7}{}⟦{\mathrm{°C}}⟧{,}{"05:00"}{=}{8}{}⟦{\mathrm{°C}}⟧{,}{"22:00"}{=}{7}{}⟦{\mathrm{°C}}⟧{,}{"15:00"}{=}{12}{}⟦{\mathrm{°C}}⟧{,}{"12:00"}{=}{11}{}⟦{\mathrm{°C}}⟧{,}{"21:00"}{=}{7}{}⟦{\mathrm{°C}}⟧{,}{"06:00"}{=}{8}{}⟦{\mathrm{°C}}⟧{,}{"20:00"}{=}{7}{}⟦{\mathrm{°C}}⟧{,}{"13:00"}{=}{12}{}⟦{\mathrm{°C}}⟧{,}{"07:00"}{=}{8}{}⟦{\mathrm{°C}}⟧{,}{"00:00"}{=}{7}{}⟦{\mathrm{°C}}⟧{,}{"09:00"}{=}{8}{}⟦{\mathrm{°C}}⟧{,}{"19:00"}{=}{8}{}⟦{\mathrm{°C}}⟧{,}{"08:00"}{=}{7}{}⟦{\mathrm{°C}}⟧{,}{"01:00"}{=}{7}{}⟦{\mathrm{°C}}⟧{,}{"18:00"}{=}{9}{}⟦{\mathrm{°C}}⟧{,}{"17:00"}{=}{10}{}⟦{\mathrm{°C}}⟧{,}{"02:00"}{=}{7}{}⟦{\mathrm{°C}}⟧{,}{"11:00"}{=}{10}{}⟦{\mathrm{°C}}⟧{,}{"16:00"}{=}{11}{}⟦{\mathrm{°C}}⟧{,}{"10:00"}{=}{9}{}⟦{\mathrm{°C}}⟧{,}{"03:00"}{=}{7}{}⟦{\mathrm{°C}}⟧\right]\right)$ (21)