Change Datatype of Column Entries - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.

Online Help

All Products    Maple    MapleSim


DataFrame/SubsDatatype

change the datatype for a column in a DataFrame

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

SubsDatatype( DF, index, newdatatype, options )

Parameters

DF

-

a DataFrame object

index

-

name, string or integer value; specifies the column index for the chosen column

newdatatype

-

type; the new datatype for the given column

Options

• 

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

Description

• 

The SubsDatatype command changes the datatype of the entries in a given column of a DataFrame as well as the indicated datatype of the column.

• 

Internally, the DataFrame/SubsDatatype command uses the DataSeries/SubsDatatype command to change the datatype.

• 

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.

> 

genus≔Rubus,Vitis,Fragaria:

> 

energy≔220,288,136:

> 

carbohydrates≔11.94,18.1,7.68:

> 

top_producer≔Russia,China,USA:

> 

berries≔DataFrame⁡energy|carbohydrates|top_producer|genus,columns=Energy,Carbohydrates,`Top Producer`,Genus,rows=Raspberry,Grape,Strawberry,datatypes=integer,float,anything,string

berries≔EnergyCarbohydratesTop ProducerGenusRaspberry22011.9400000000000RussiaRubusGrape28818.1000000000000ChinaVitisStrawberry1367.68000000000000USAFragaria

(1)

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

> 

Datatypes⁡berries

integer,float8,anything,string

(2)

You can change the datatype of the Energy column to float:

> 

SubsDatatype⁡berries,Energy,float

EnergyCarbohydratesTop ProducerGenusRaspberry220.11.9400000000000RussiaRubusGrape288.18.1000000000000ChinaVitisStrawberry136.7.68000000000000USAFragaria

(3)

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

> 

berries≔SubsDatatype⁡berries,Energy,float

berries≔EnergyCarbohydratesTop ProducerGenusRaspberry220.11.9400000000000RussiaRubusGrape288.18.1000000000000ChinaVitisStrawberry136.7.68000000000000USAFragaria

(4)
> 

Datatype⁡berriesEnergy

float8

(5)

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

> 

berries≔SubsDatatype⁡berries,Genus,name,`=`⁡conversion,x↦convert⁡x,name

berries≔EnergyCarbohydratesTop ProducerGenusRaspberry220.11.9400000000000RussiaRubusGrape288.18.1000000000000ChinaVitisStrawberry136.7.68000000000000USAFragaria

(6)
> 

berries≔SubsDatatype⁡berries,`Top Producer`,string,`=`⁡conversion,x↦convert⁡x,string

berries≔EnergyCarbohydratesTop ProducerGenusRaspberry220.11.9400000000000RussiaRubusGrape288.18.1000000000000ChinaVitisStrawberry136.7.68000000000000USAFragaria

(7)
> 

Datatypes⁡berries

float8,float8,string,name

(8)

Compatibility

• 

The DataFrame/SubsDatatype command was introduced in Maple 2017.

• 

For more information on Maple 2017 changes, see Updates in Maple 2017.

See Also

DataFrame/Datatypes

DataSeries/Datatype

DataSeries/SubsDatatype