सामग्री पर जाएँ

लेसन 10 · Cleaning and Transforming

Cleaning Text and Dates in KNIME

Normalize messy text, split and combine columns, parse text into KNIME date and time values with String to Date&Time, and avoid ambiguous date formats.

Text typed by people is inconsistent: " Berlin", "berlin", and "BERLIN" are three different values to a computer. Dates are worse, since 03/04/2026 means two different days in different countries. This lesson shows how to make both predictable.

Normalize text

A few operations cover most cases:

  1. Trim extra spaces at the start and end.
  2. Collapse repeated spaces inside the text.
  3. Standardize case, such as all upper or all lower.
  4. Replace variants with a standard value.

In KNIME you can do this with the String Manipulation node or the Expression node. The two use different syntax and function names, so open the function list in the node you choose. A typical String Manipulation formula that trims and upper-cases a country column looks like this:

TEXT
upperCase(strip($country$))

If the list of variants is long, do not build a tower of replace functions. Create a small mapping table with two columns, such as raw and standard, and use a lookup node such as Value Lookup to add the standard value. Business users can then edit the table without changing the workflow.

Python Stand-in: normalize and map city names

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice the unmapped value. A good workflow sends unmatched rows to a review list rather than silently keeping them.

Split and combine

Names like Last, First or codes like DE-BY-80331 often need splitting. KNIME's Cell Splitter node splits a column on a delimiter into several columns, and expression functions can combine columns back. Before splitting, check how many parts each value has: some might have two and others three.

For irregular patterns, such as pulling an order number from a sentence, regular expressions help. Test them on tricky samples first.

Python Stand-in: extract order codes with a regular expression

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The pattern requires four digits, so ORD-7 is ignored. Whether that is right depends on your data.

Dates and times

KNIME has real date and time types. A text value such as "30.11.2026" is just text until you convert it with String to Date&Time. In its dialog you pick a format from a list or type a pattern, and choose which date or time type to produce. KNIME has replaced several date and time nodes over the years, so older workflows may use versions now marked deprecated. Pick the current node in the node repository.

Common pattern letters look like this:

Letters Meaning
yyyy Four-digit year
MM Two-digit month
dd Two-digit day
HH Hour on a 24-hour clock
mm Minutes

Case matters: MM is month, while mm is minutes. Many "my dates are all January" bugs come from this.

Ambiguous dates

Month first 03/04 is March 4
Day first 03/04 is April 3
ISO 2026-03-04 is clear

Confirm the source format with its owner

1 / 2
Python Stand-in: one string, two dates

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python pattern codes differ from KNIME's, but the lesson holds: the format you declare decides what a value means.

Working with dates

Once columns are real dates, you can extract parts such as year and month, calculate differences, and filter by date ranges with KNIME's date and time nodes. If timestamps come from several countries, decide which time zone they use before comparing them. Store a zone with the data when possible, and group by day only after converting to the zone your report needs.

Check the earliest and latest date after every conversion. A value from 1900 or a future year usually means a wrong format or a bad input.

Invisible characters

Some problems cannot be seen. Text copied from a web page may contain non-breaking spaces or tabs, and files from different operating systems may carry stray line break characters. Two values that look identical then fail to match. If a join or filter misses rows that should match, compare the lengths of the two values. A longer value than expected is a clue that something hidden is there. Replace those characters explicitly, and record which ones you replaced.

Keeping originals

Do not overwrite raw text too early. Keep the original column and add a cleaned one, such as city_clean. Reviewers can then compare them, and when a mapping rule is wrong, you can fix it without reloading data. Once the workflow is trusted, remove the raw column near the end if nobody needs it.

Date arithmetic traps

Real dates make calculations possible, but some questions are not as simple as they look. "One month later" from January 31 has no obvious answer. "Days between" depends on whether you count the first day. Weeks may start on Monday or Sunday, and week numbering at the start of a year differs between conventions. Ask the people who will use the numbers which definition they mean, then check your workflow on dates around month ends, year ends, and the end of February in a leap year.

Practice task

Collect ten messy city names and five date strings in two formats. Normalize the cities with a mapping table, and send unmapped names to a review output. Convert only dates whose format you know, and keep the rest in a separate list with the reason. A workflow that admits it does not know is better than one that guesses.

Case and language

Changing case is less simple than it appears. Some languages have letters whose upper and lower case forms do not map one to one, and sorting rules differ between languages. For matching codes this rarely matters, but for names and free text it can. Do not use a case change as the only test of whether two people are the same. If your data covers many languages, test with real examples from each, and keep the original text for display. Use the normalized version only as a hidden key for matching.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Why use a mapping table instead of many nested replace functions?

    A table keeps rules in one editable place.
  2. 2. In many date patterns, what does MM usually mean?

    Uppercase MM is month; lowercase mm is minutes.
  3. 3. How should you handle a file with dates like 03/04/2026?

    The same string means different days under different formats.

Summary

  • Trim, collapse spaces, standardize case, and map variants.
  • Send unmapped values to review.
  • Split with Cell Splitter or regular expressions, and check unusual rows.
  • Convert text with String to Date&Time using the correct pattern.
  • Verify date ranges and time zones.

Next: Joining and Concatenating Tables

आपकी प्रगति इसी ब्राउज़र में सेव होती है। खाते की ज़रूरत नहीं है।