Group Method (Python)

Groups selected category labels or group labels, creates a grouping level, and inserts a grouping label.

  • The selection must be category or group labels.
  • After the execution of this method, the inserted grouping label is selected and has the default label of Group Label.
  • If a new group level is inserted, labels on the same and lower levels are demoted one level. (For column labels, the row index increases by one; for row labels, the column index increases by one.)

Syntax

SpssPivotTable.Group()

Example

This example assumes that PivotTable is an SpssPivotTable object, selects category column labels Clerical and Custodial, and groups them under the label of Non-Managerial.

ColumnLabels = PivotTable.ColumnLabelArray()

#Select the category column labels Clerical and Custodial:
PivotTable.ClearSelection()
for i in range(ColumnLabels.GetNumRows()):
   for j in range(ColumnLabels.GetNumColumns()):
		   if ColumnLabels.GetValueAt(i,j) in ["Clerical","Custodial"]:
			   ColumnLabels.SelectLabelAt(i,j) 
	
#Group the categories and assign a group label:
PivotTable.Group()
for i in range(ColumnLabels.GetNumRows()):
   for j in range(ColumnLabels.GetNumColumns()):
		   if ColumnLabels.GetValueAt(i,j)=="Group Label":
			   ColumnLabels.SetValueAt(i,j,"Non-Managerial")