The final bit of code creates the output. The title for this output will be "Wordcounts". A BasePivotTable is created in the next line with an argument for the Title (displayed in the output) and the templateName. The templateName specificies the OMS (Output Management System) table subtype. This argument is required for every pivot table, but in this example we are not working with the OMS. The SetDefaultFormatSpec method determines the format of the table and Count was used as it is appropriate for this case. For a table of formatting options please see page 34 of the Python Reference Guide for IBM SPSS Statistics.
The next few lines populate the data in the table we created. First, we label the row dimension ("Words"), then populate the labels with the keys at index 0 from the output from the freqs() function. Next, we label the next column "Counts" and iterate over the values at index 1 to populate data in this column. The Python Reference Guide also has detailed information on the SimplePivotTable method.
Finally, we end the procedure and end the program with SPSS syntax.