Using de-pivoting

As with pivoting, de-pivoting is best understood by looking at a picture. The previous screenshot showed how pivoting works, and de-pivoting, as its name implies, can be seen as a reverse operation. Refer to the pivoting.xml process provided with this book.

Refer to the screenshot in the Using pivoting section and reverse the operation. The result contains data that has multiple values in a single example set, perhaps recorded over a period of time. What de-pivoting will do is to turn the example set back into name-value pairs with one example for each in the original example set. So if the original example set contains four attributes in addition to an id that ties them together, the de-pivoted result will contain four examples for each id. Each of these examples will have a common id, an attribute with a value based on the name of the original attribute, and a value derived from the intersection of the original attribute and the common id.

The parameters needed to make the De-Pivot operator work are shown in the following screenshot:

Using de-pivoting

The index attribute is the name of an attribute that will be created as a result of the de-pivot operation. The attribute name parameter is set to value, and this will be the name of an attribute that will be created in the de-pivot result. A regular expression is used to select the attributes to include in the result; in this case the expression is value.* (in simple English, this means match an attribute that begins with value and has zero or more arbitrary characters after it). This selects the four attributes beginning with value.

This results in the example set are as shown in the following screenshot:

Using de-pivoting

The only difference between this and the original example set are the values for the name attributes. These are all preceded with value_ because this is a faithful reproduction of the source attributes. This can be resolved by using a Replace operator, which can be seen in the pivoting.xml process.

The following points should be noted for the parameters to the De-Pivot operator:

  • The create nominal index checkbox must be checked if the values of the index attribute are going to be nominal (which they are in this case).
  • The index attribute field itself (in this case, name) has as many unique values as there are attributes that match the expression contained within the list for the attribute name. For the example given, there are four attributes that match the expression, hence there are four unique values for the attribute.
  • Each matched attribute from the attribute name list creates a name in the index column, and the corresponding value is created from the intersection of the matched attribute and the ID.

Practice makes perfect and the best way to get to grips with this operator is to try it. Windowing data

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset