DataFrame/SubsDatatype
change the datatype for a column in a DataFrame
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
SubsDatatype( DF, index, newdatatype, options )
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
conversion : procedure; specifies a procedure to be mapped onto the elements in the given column. This option is entered in the form conversion = procedure.
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.
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
You can get the data types for the columns with the Datatypes command.
Datatypes⁡berries
integer,float8,anything,string
You can change the datatype of the Energy column to float:
SubsDatatype⁡berries,Energy,float
EnergyCarbohydratesTop ProducerGenusRaspberry220.11.9400000000000RussiaRubusGrape288.18.1000000000000ChinaVitisStrawberry136.7.68000000000000USAFragaria
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
Datatype⁡berriesEnergy
float8
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≔SubsDatatype⁡berries,`Top Producer`,string,`=`⁡conversion,x↦convert⁡x,string
float8,float8,string,name
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
Download Help Document