Number Class (Python)
spss.CellText.Number(value,formatspec,varIndex). Used
to specify a numeric value for a category or a cell in a pivot table. The
argument value specifies the numeric value. You can also pass
a string representation of a numeric value, a Python time.struct_time
object,
or a Python datetime.datetime
object to this argument.
The optional argument formatspec is of the form spss.FormatSpec.format
where format
is
one of those listed in the table below--for example, spss.FormatSpec.Mean
.
You can also specify an integer code for formatspec, as in
the value 5
for Mean
. The argument varIndex is
the index of a variable in the active dataset whose format is used
to determine details of the resulting format. varIndex is only
used in conjunction with formatspec and is required when specifying
one of the following formats: Mean
, Variable
, StdDev
, Difference
,
and Sum
. Index values represent position in the active
dataset, starting with 0 for the first variable in file order.
- When formatspec is omitted, the default format is used.
You can set the default format with the SetDefaultFormatSpec method and retrieve the default
with the GetDefaultFormatSpec method. Instances of the
BasePivotTable
class have an implicit default format ofGeneralStat
. - You can obtain a numeric representation of a
CellText.Number
object using the toNumber method, and you can use the toString method to obtain a string representation.
- When specifying cell values with Python
time.struct_time
ordatetime.datetime
objects, the value will be displayed in seconds--specifically, the number of seconds from October 14, 1582. You can change the format of a cell to a datetime format using the SetNumericFormatAt method (Python) Python Scripting method.
Example
from spss import CellText
from spss import FormatSpec
table = spss.BasePivotTable("Table Title",
"OMS table subtype")
table.Append(spss.Dimension.Place.row,"rowdim")
table.Append(spss.Dimension.Place.column,"coldim")
table[(CellText.String("row1"),CellText.String("col1"))] = \
CellText.Number(25.632,FormatSpec.Mean,2)
table[(CellText.String("row2"),CellText.String("col1"))] = \
CellText.Number(23.785,FormatSpec.Mean,2)
In this example, cell values are displayed in the format used for mean values. The format of the variable with index 2 in the active dataset is used to determine the details of the resulting format.
Format name | Code |
---|---|
Coefficient | 0 |
CoefficientSE | 1 |
CoefficientVar | 2 |
Correlation | 3 |
GeneralStat | 4 |
Mean | 5 |
Count | 6 |
Percent | 7 |
PercentNoSign | 8 |
Proportion | 9 |
Significance | 10 |
Residual | 11 |
Variable | 12 |
StdDev | 13 |
Difference | 14 |
Sum | 15 |
Suggestions for Choosing a Format
- Consider using
Coefficient
for unbounded, unstandardized statistics; for instance, beta coefficients in regression. -
Correlation
is appropriate for statistics bounded by –1 and 1 (typically correlations or measures of association). - Consider using
GeneralStat
for unbounded, scale-free statistics; for instance, beta coefficients in regression. -
Mean
is appropriate for the mean of a single variable, or the mean across multiple variables. -
Count
is appropriate for counts and other integers such as integer degrees of freedom. -
Percent
andPercentNoSign
are both appropriate for percentages.PercentNoSign
results in a value without a percentage symbol (%). -
Significance
is appropriate for statistics bounded by 0 and 1 (for example, significance levels). - Consider using
Residual
for residuals from cell counts. -
Variable
refers to a variable’s print format as given in the data dictionary and is appropriate for statistics whose values are taken directly from the observed data (for instance, minimum, maximum, and mode). -
StdDev
is appropriate for the standard deviation of a single variable, or the standard deviation across multiple variables. -
Sum
is appropriate for sums of single variables. Results are displayed using the specified variable’s print format.