SetCellsByRow Method (Python)
.SetCellsByRow(rowlabels,cells). Sets cell values
for the row specified by a set of categories, one for each row dimension. The
argument rowlabels specifies the set of categories that defines
the row--a single value, or a list or tuple. The argument cells is
a tuple or list of cell values. Row 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 row dimensions, the order of categories in the rowlabels argument is the order in which their respective dimensions were added (appended or inserted) to the table. For example, given two row dimensions rowdim1 and rowdim2 added in the order rowdim1 and rowdim2, the first element in rowlabels should be the category for rowdim1 and the second the category for rowdim2.
- You can only use the
SetCellsByRow
method with pivot tables that have one column dimension.
Example
from spss import CellText
table = spss.BasePivotTable("Table Title",
"OMS table subtype")
coldim=table.Append(spss.Dimension.Place.column,"coldim")
rowdim1=table.Append(spss.Dimension.Place.row,"rowdim-1")
rowdim2=table.Append(spss.Dimension.Place.row,"rowdim-2")
cat1=CellText.String("rowdim1:A")
cat2=CellText.String("rowdim1:B")
cat3=CellText.String("rowdim2:A")
cat4=CellText.String("rowdim2:B")
cat5=CellText.String("C")
cat6=CellText.String("D")
table.SetCategories(rowdim1,[cat1,cat2])
table.SetCategories(rowdim2,[cat3,cat4])
table.SetCategories(coldim,[cat5,cat6])
table.SetCellsByRow((cat1,cat3),
[CellText.Number(11),
CellText.Number(12)])
table.SetCellsByRow((cat1,cat4),
[CellText.Number(21),
CellText.Number(22)])
table.SetCellsByRow((cat2,cat3),
[CellText.Number(31),
CellText.Number(32)])
table.SetCellsByRow((cat2,cat4),
[CellText.Number(41),
CellText.Number(42)])
- 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 SetCellsByRow
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.