Page tree

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Release 5.1


Contents:

   

Contents:


Unlike other types of data, text data has very few restrictions on the kinds of values that appear in a cell. In the application, this data is typically inferred as String data type. As a result, finding string values that mean the same thing can be a challenge, as minor differences in their content or structure can invalidate a match.

This section provides some methods for matching text values.

  • Some target systems may impose limits on the lengths of imported values. For more information on managing the lengths of your strings, see Manage String Lengths.

Example Data

In the following example, you can see that there are minor differences between the String values in each row of the dataset. These differences are captured in the Description column.

StringDescription
My StringBase string: 'My String'
My String extraBase string + ' extra'
 My StringA space in front of base string
My String A space after base string
MyStringNo space between the two words of base string
My  StringTwo spaces between the two words of base string
My StringBase string + a tab character
My String
 
Base string + a return character
My String
 
Base string + a newline character

When this data is imported, it looks like the following, after minor cleanup:

Figure: Example data after import

Notes:

  • You can see that white space is demarcated in the imported data. In particular, the line item with two spaces between the words is accurately represented in the data grid.
  • Newlines, carriage returns, tabs, and other non-visible characters are represented with icons.

To normalize these text values, you can use some of the techniques listed on this page to match the problematic string values in this dataset and correct them, as needed.

Finer-Grained Controls

For closer control over string matching and cleanup, you can apply individual transforms to your column of string data. The sections below outline a number of techniques for identifying matches and cleaning up your data.

Trim strings

NOTE: Before you begin matching data, you should perform a TRIM transform to remove whitespace at the beginning and end of the string, unless the whitespace is significant to the meaning and usage of the string data. 

When transforming strings, a key step is to trim off the whitespace at the beginning and ending of the string. For the above dataset, you can use the following command to remove these whitespaces:

Transformation Name Edit column with formula
Parameter: Columns *
Parameter: Formula TRIM($col)

The above transform uses the following special values, which are available for some transforms like set:

Special ValueDescription
*For the Columns textbox, you can use this wildcard to reference all columns in the dataset.
$colWhen multiple columns are referenced in a transform, this special value allows you to reference the source column in a replacement value.

The previewed data looks like the following, in which five strings are modified and now match the base string:

Figure: Trim data to improve matches

To remove all whitespace, including spaces in between, you can use the REMOVEWHITESPACE function. See REMOVEWHITESPACE Function.

Use missing or mismatched value presets

The platform language,  Wrangle, provides presets to identify missing or mismatched values in a selection of data.

Tip: In a column's histogram, click the missing or mismatched categories to trigger a set of suggestions.

Missing values preset: The following transform replaces missing URL values with the text string http://www.example.com. The preset ISMISSING([Primary_WebSite_or_URL]) identifies the rows missing data in the specified column:

Transformation Name Edit column with formula
Parameter: Columns Primary_Website_or_URL
Parameter: Formula IF(ISMISSING([Primary_Website_or_URL]),'http://www.example.com',$col)

For more information, see Find Missing Data.

NOTE: If the data type for the column is URL, then the replacement text string must be a valid URL, or the new data is registered as mismatched with the data type.

Mismatched values preset: This transform converts to 00000 all values in the Zip column that are mismatched against the Zipcode data type. In this case, the preset ISMISMATCHED(Zip, ['Zipcode']) identifies the mismatched values in the column, as compared to the Zipcode data type:

Transformation Name Edit column with formula
Parameter: Columns Zip
Parameter: Formula IF(ISMISMATCHED(Zip, ['Zipcode']),'00000',$col)

For more information, see Find Bad Data.

Remove a specific sub-string

An entry in the example data contains an additional word: My String extra. You can use a simple replace command to remove it: 

Transformation Name Replace text or patterns
Parameter: Column String
Parameter: Find ' extra'
Parameter: Replace with ''
Parameter: Match all occurrences true

The global parameter causes the replacement to be applied to all instances found within a cell value. Otherwise, the replacement occurs only on the first instance.

Replace double spaces

There are multiple ways of removing double spaces, or any pattern, from text values. For best results, you should limit this change to individual columns.

NOTE: For matching string patterns that are short in length, you should be careful to define the scope of match. For example, to remove double spaces from your dataset, you should limit the columns to just the ones containing string values. If you applied the change to all columns in the dataset, meaningful uses of double spacing could be corrupted, such as in JSON data fields.

Transformation Name Replace text or patterns
Parameter: Column String
Parameter: Find ' '
Parameter: Replace with ''
Parameter: Match all occurrences true

Break out CamelCase

CamelCase refers to text in which multiple words are joined together by removing the spaces between them. In the example data, the entry MyString is an example of CamelCase. 

NOTE: Regular expressions are very powerful pattern-matching tools. If they are poorly specified in a transform, they can have unexpected results. Please use them with caution.

You can use Alteryx patterns to break up CamelCase entries in a column of values. The following transforms use regular expressions to identify patterns in a set of values: 

Transformation Name Replace text or patterns
Parameter: Column String
Parameter: Find `({alpha})({upper})`
Parameter: Replace with '$1 $2'
Parameter: Match all occurrences true

The first transform locates all instances of uppercase letters followed by lower-case letters. Each instance is replaced by a space, followed by the found string ($2). For more information, see Text Matching.

Reduce strings by words

Remove last word:

For example, you need to remove the last word of a string and the space before it. You can use the following replace transform to do that:

Transformation Name Replace text or patterns
Parameter: Column String
Parameter: Find ` {alpha}+{end}`
Parameter: Replace with ''
Parameter: Match all occurrences true

When the above is previewed, however, you might notice that ending punctuation is not captured. For example, periods, exclamation points, and question marks at the end of your values are not captured in the Alteryx pattern. To capture those values, the on parameter must be expanded: 

Transformation Name Replace text or patterns
Parameter: Column String
Parameter: Find ` {alpha}+({[?.!;\)]}|){end}`
Parameter: Replace with ''
Parameter: Match all occurrences true

In the second version, a capture group has been inserted in the middle of the on parameter value, as specified by the contents of the parentheses:

  • The bracket-colon notation denotes a set of possible individual characters that could appear at this point in the pattern.
    • Note the backward slash before the right parenthesis in the capture group. This value is used to escape a value, so that this parenthesis is interpreted as another character, instead of the end of the capture group.
  • The vertical pipe (|) denotes a logical OR, meaning that the specified individual characters could appear or the value after the vertical pipe. 
  • Since the value after the vertical pipe is missing, this capture group finds values with or without punctuation at the end of the line.

Reduce total number of words:

You need to cut each value in a column down to a maximum of two words. You can use the following to identify the first two words using capture groups in a Alteryx pattern and then write that pattern back out, dropping the remainder of the column value:

Transformation Name Replace text or patterns
Parameter: Column String
Parameter: Find `{start}({alpha}* )({alpha}*) ({any}*{end})`
Parameter: Replace with '$1$2'
Parameter: Match all occurrences true

For the on pattern:

  • The start pattern identifies the start of each value in the String column.
  • The two alpha capture groups identify the first two words in the string. Note that the space after the second capture group is specified outside of the capture group; if it was part of the capture group, a trailing space is written in the replacement value.
  • The final capture group identifies the remainder of the value in the cell.
    • any captures any single character.
    • The wildcard asterisk captures all values between the any character and the end of the value.

  • No labels

This page has no comments.