SetCellsByColumn Method (Python)
.SetCellsByColumn(collabels,cells). Sets cell values
for the column specified by a set of categories, one for each column
dimension. The argument collabels specifies the set of
categories that defines the column--a single value, or a list or tuple.
The argument cells is a tuple or list of cell values. Column
categories and cell values must be specified as CellText objects
(one of CellText.Number
, CellText.String
, CellText.VarName
,
or CellText.VarValue
).
- For tables with multiple column dimensions, the order of categories in the collabels argument is the order in which their respective dimensions were added (appended or inserted) to the table. For example, given two column dimensions coldim1 and coldim2 added in the order coldim1 and coldim2, the first element in collabels should be the category for coldim1 and the second the category for coldim2.
- You can only use the
SetCellsByColumn
method with pivot tables that have one row dimension.
Example
from spss import CellText
table = spss.BasePivotTable("Table Title",
"OMS table subtype")
rowdim=table.Append(spss.Dimension.Place.row,"rowdim")
coldim1=table.Append(spss.Dimension.Place.column,"coldim-1")
coldim2=table.Append(spss.Dimension.Place.column,"coldim-2")
cat1=CellText.String("coldim1:A")
cat2=CellText.String("coldim1:B")
cat3=CellText.String("coldim2:A")
cat4=CellText.String("coldim2:B")
cat5=CellText.String("C")
cat6=CellText.String("D")
table.SetCategories(coldim1,[cat1,cat2])
table.SetCategories(coldim2,[cat3,cat4])
table.SetCategories(rowdim,[cat5,cat6])
table.SetCellsByColumn((cat1,cat3),
[CellText.Number(11),
CellText.Number(21)])
table.SetCellsByColumn((cat1,cat4),
[CellText.Number(12),
CellText.Number(22)])
table.SetCellsByColumn((cat2,cat3),
[CellText.Number(13),
CellText.Number(23)])
table.SetCellsByColumn((cat2,cat4),
[CellText.Number(14),
CellText.Number(24)])
- In this example, Number objects are used to specify numeric values
for the cells. Values will be formatted using the table's default
format. Instances of the
BasePivotTable
class have an implicit default format ofGeneralStat
. You can change the default format using the SetDefaultFormatSpec method, or you can override the default by explicitly specifying the format, as in:CellText.Number(22,spss.FormatSpec.Correlation)
. See the topic Number Class (Python) for more information.

Examples of using the SetCellsByColumn
method
are most easily understood in the context of going through the steps
to create a pivot table. See the topic General Approach to Creating Pivot Tables (Python) for more information.