SetCategories Method (Python)

.SetCategories(dim,categories). Sets categories for the specified dimension. The argument dim is a reference to the dimension object for which categories are to be set. Dimensions are created with the Append or Insert method. The argument categories is a single value or a sequence of unique values, each of which is a CellText object (one of CellText.Number, CellText.String, CellText.VarName, or CellText.VarValue).

  • In addition to defining category values for a specified dimension, SetCategories sets the pivot table object's value of the currently selected category for the specified dimension. In other words, calling SetCategories also sets a pointer to a category in the pivot table. When a sequence of values is provided, the currently selected category (for the specified dimension) is the last value in the sequence. For an example of using currently selected dimension categories to specify a cell, see the SetCell method.
  • Once a category has been defined, a subsequent call to SetCategories (for that category) will set that category as the currently selected one for the specified dimension.

Example

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

rowdim=table.Append(spss.Dimension.Place.row,"rowdim")
coldim=table.Append(spss.Dimension.Place.column,"coldim")

table.SetCategories(rowdim,[spss.CellText.String("row1"),
                            spss.CellText.String("row2")])
table.SetCategories(coldim,[spss.CellText.String("column1"),
                            spss.CellText.String("column2")])

Examples of using the SetCategories 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.