DataSeries/SubsDatatype - Maple Programming Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : Statistics and Data Analysis : DataFrames and DataSeries : DataSeries Commands : DataSeries/SubsDatatype

DataSeries/SubsDatatype

change the datatype of a data series

 Calling Sequence SubsDatatype( DS, newdatatype, options )

Parameters

 DF - a DataSeries object newdatatype - type; the new datatype for the data series

Options

 • conversion : procedure; specifies a procedure to be mapped onto the elements in the given data series. This option is entered in the form conversion = procedure.

Description

 • The SubsDatatype command changes the datatype of the entries in a DataSeries as well as the indicated datatype of the data series.
 • If the conversion option is given, then the values in the DataSeries are converted by this conversion procedure. Otherwise, they are typically not modified, but there are exceptions. Internally, a new Array is constructed with the given datatype, and the current values are used to initialize this Array; this is the step where an automatic conversion could take place.

Examples

Consider some data on berries.

 > $\mathrm{genus}≔\mathrm{DataSeries}\left(⟨"Rubus","Vitis","Fragaria"⟩,\mathrm{labels}=\left[\mathrm{Raspberry},\mathrm{Grape},\mathrm{Strawberry}\right],\mathrm{datatype}=\mathrm{string}\right):$
 > $\mathrm{energy}≔\mathrm{DataSeries}\left(⟨220,288,136⟩,\mathrm{labels}=\left[\mathrm{Raspberry},\mathrm{Grape},\mathrm{Strawberry}\right],\mathrm{datatype}=\mathrm{integer}\right):$
 > $\mathrm{carbohydrates}≔\mathrm{DataSeries}\left(⟨11.94,18.1,7.68⟩,\mathrm{labels}=\left[\mathrm{Raspberry},\mathrm{Grape},\mathrm{Strawberry}\right],\mathrm{datatype}=\mathrm{float}\right):$
 > $\mathrm{top_producer}≔\mathrm{DataSeries}\left(⟨\mathrm{Russia},\mathrm{China},\mathrm{USA}⟩,\mathrm{labels}=\left[\mathrm{Raspberry},\mathrm{Grape},\mathrm{Strawberry}\right],\mathrm{datatype}=\mathrm{name}\right):$

The individual DataSeries are displayed more compactly in a DataFrame:

 > $\mathrm{berries}≔\mathrm{DataFrame}\left(\mathrm{Energy}=\mathrm{energy},\mathrm{Carbohydrates}=\mathrm{carbohydrates},\mathrm{TopProducer}=\mathrm{top_producer},\mathrm{Genus}=\mathrm{genus}\right)$
 ${\mathrm{berries}}{≔}\left[\begin{array}{ccccc}{}& {\mathrm{Energy}}& {\mathrm{Carbohydrates}}& {\mathrm{TopProducer}}& {\mathrm{Genus}}\\ {\mathrm{Raspberry}}& {220}& {11.9400000000000}& {\mathrm{Russia}}& {"Rubus"}\\ {\mathrm{Grape}}& {288}& {18.1000000000000}& {\mathrm{China}}& {"Vitis"}\\ {\mathrm{Strawberry}}& {136}& {7.68000000000000}& {\mathrm{USA}}& {"Fragaria"}\end{array}\right]$ (1)

You can get the data types for the columns with the Datatypes command.

 > $\mathrm{Datatypes}\left(\mathrm{berries}\right)$
 $\left[{\mathrm{integer}}{,}{{\mathrm{float}}}_{{8}}{,}{\mathrm{name}}{,}{\mathrm{string}}\right]$ (2)
 > $\mathrm{Datatype}\left(\mathrm{carbohydrates}\right)$
 ${{\mathrm{float}}}_{{8}}$ (3)

You can change the datatype of the Energy data series to float:

 > $\mathrm{SubsDatatype}\left(\mathrm{energy},\mathrm{float}\right)$
 $\left[\begin{array}{cc}{\mathrm{Raspberry}}& {220.}\\ {\mathrm{Grape}}& {288.}\\ {\mathrm{Strawberry}}& {136.}\end{array}\right]$ (4)

This does not change the datatype in place. To permanently change the datatype:

 > $\mathrm{energy}≔\mathrm{SubsDatatype}\left(\mathrm{energy},\mathrm{float}\right)$
 ${\mathrm{energy}}{≔}\left[\begin{array}{cc}{\mathrm{Raspberry}}& {220.}\\ {\mathrm{Grape}}& {288.}\\ {\mathrm{Strawberry}}& {136.}\end{array}\right]$ (5)
 > $\mathrm{Datatype}\left(\mathrm{energy}\right)$
 ${{\mathrm{float}}}_{{8}}$ (6)

When working with strings or name conversions, it may be necessary to supply an explicit  conversion for the values in the data series:

 > $\mathrm{genus}≔\mathrm{SubsDatatype}\left(\mathrm{genus},\mathrm{name},\mathrm{=}\left(\mathrm{conversion},x↦\mathrm{convert}\left(x,\mathrm{name}\right)\right)\right)$
 ${\mathrm{genus}}{≔}\left[\begin{array}{cc}{\mathrm{Raspberry}}& {\mathrm{Rubus}}\\ {\mathrm{Grape}}& {\mathrm{Vitis}}\\ {\mathrm{Strawberry}}& {\mathrm{Fragaria}}\end{array}\right]$ (7)
 > $\mathrm{Datatype}\left(\mathrm{genus}\right)$
 ${\mathrm{name}}$ (8)
 > $\mathrm{top_producer}≔\mathrm{SubsDatatype}\left(\mathrm{top_producer},\mathrm{string},\mathrm{=}\left(\mathrm{conversion},x↦\mathrm{convert}\left(x,\mathrm{string}\right)\right)\right)$
 ${\mathrm{top_producer}}{≔}\left[\begin{array}{cc}{\mathrm{Raspberry}}& {"Russia"}\\ {\mathrm{Grape}}& {"China"}\\ {\mathrm{Strawberry}}& {"USA"}\end{array}\right]$ (9)
 > $\mathrm{Datatype}\left(\mathrm{top_producer}\right)$
 ${\mathrm{string}}$ (10)
 > $\mathrm{berries}≔\mathrm{DataFrame}\left(\mathrm{Energy}=\mathrm{energy},\mathrm{Carbohydrates}=\mathrm{carbohydrates},\mathrm{TopProducer}=\mathrm{top_producer},\mathrm{Genus}=\mathrm{genus}\right)$
 ${\mathrm{berries}}{≔}\left[\begin{array}{ccccc}{}& {\mathrm{Energy}}& {\mathrm{Carbohydrates}}& {\mathrm{TopProducer}}& {\mathrm{Genus}}\\ {\mathrm{Raspberry}}& {220.}& {11.9400000000000}& {"Russia"}& {\mathrm{Rubus}}\\ {\mathrm{Grape}}& {288.}& {18.1000000000000}& {"China"}& {\mathrm{Vitis}}\\ {\mathrm{Strawberry}}& {136.}& {7.68000000000000}& {"USA"}& {\mathrm{Fragaria}}\end{array}\right]$ (11)
 > $\mathrm{Datatypes}\left(\mathrm{berries}\right)$
 $\left[{{\mathrm{float}}}_{{8}}{,}{{\mathrm{float}}}_{{8}}{,}{\mathrm{string}}{,}{\mathrm{name}}\right]$ (12)

Compatibility

 • The DataSeries/SubsDatatype command was introduced in Maple 2017.
 • For more information on Maple 2017 changes, see Updates in Maple 2017.

 See Also