Skip to content

Language: Cast Statement

Maurice HT Ling edited this page Dec 6, 2015 · 12 revisions

Casting data values of one or more series in a data frame from one data type to another.

For example, casting from string (characters) to floating point values. The former (string or character data type) cannot be used for non-equality comparisons as it does not make sense to compare whether "apple" is more than or less than "APPLE". String or character data type can only be used for equality comparison. The latter (floating point values) can be used for non-equality comparisons; such as, whether 5 is more than 4.

Syntax:

  1. CAST id_list IN ID AS datatype

where

  • id_list = "all" | ID | id_list, ID
  • ID is (1) the name of the data series, or (2) name of the data frame
  • datatype = "alpha" | "nonalpha" | "float" | "real" | "integer"
  • "alpha" will cast the series into string or character data type
  • "nonalpha" will cast the series into float data type
  • "float" or "real" will cast the series into float data type
  • "integer" will cast the series into integer data type

Example (in https://github.com/mauriceling/tapps/blob/master/examples/example_03.py):

# Set relative current working directory and load a CSV file
set rcwd data
load csv STI_2015.csv as STI

# Cast "Open" series into float data type and perform non-equality operation
cast Open in STI as nonalpha
select from STI as STI_H where Open > 3000

# Cast all series into float data type and perform non-equality operation
cast all in STI as nonalpha
select from STI as STI_02 where Volume = 0

Advanced Topics

  1. Bytecodes generated are:
    • cast