toNumber Method (Python)

This method is used to obtain a numeric representation of a CellText.Number object or a CellText.String object that stores a character representation of a numeric value, as in CellText.String("123"). Values obtained from this method can be used in arithmetic expressions. You call this method on a CellText.Number or CellText.String object.

Example

from spss import CellText
table = spss.BasePivotTable("Table Title",
                            "OMS table subtype")

table.Append(spss.Dimension.Place.row,"row dimension")
table.Append(spss.Dimension.Place.column,"column dimension")

row_cat1 = CellText.String("first row")
row_cat2 = CellText.String("second row")
col_cat1 = CellText.String("first column")
col_cat2 = CellText.String("second column")

table[(row_cat1,col_cat1)] = CellText.Number(11)
cellValue = table[(row_cat1,col_cat1)].toNumber()
table[(row_cat2,col_cat2)] = CellText.Number(2*cellValue)
  • table[(row_cat1,col_cat1)].toNumber() returns a numeric representation of the CellText object (recall that table cells are stored as CellText objects) for the cell with category values ("first row","first column").