Saltar al contenido

Lección 7 · Cleaning and Transforming

Filtering Rows and Columns in KNIME

Keep only the data you need with Row Filter, Column Filter, Expression Row Filter, Sorter, and duplicate checks, and avoid traps caused by missing values.

Real data contains more than you need: test rows, old records, internal columns, and noise. Filtering early makes workflows faster and easier to read. This lesson covers the nodes for cutting a table down.

Columns first

The Column Filter node chooses which columns continue to the next node. You can pick columns by name, and many versions also let you select by pattern or by type. Dropping unused columns early keeps previews readable and reduces memory use.

Be careful when new columns appear in the source later. In the dialog, check whether the setting means "keep exactly these" or "remove exactly these", because they treat a new column differently. If a new column holds personal data, you probably do not want it to slip through.

Related nodes let you rename columns and change their order. Renaming cust_nm to customer_name early makes everything after it easier to read.

Filtering rows

The Row Filter node keeps or removes rows that match conditions on column values. Typical conditions include equality, ranges, matching text patterns, and whether a value is missing. You can combine several conditions with "all of" or "any of" logic. Decide whether the matching rows are included or excluded; a mistake here flips your result.

Row filter questions

Which column? Check its type
Which test? Equal, range, pattern
All or any? AND versus OR
Keep or drop? Include or exclude
1 / 2

For rules too complex for the dialog, use Expression Row Filter, where you write one expression that is true for rows to keep:

TEXT
$["status"] = "paid" and $["amount"] >= 100

This is KNIME's expression syntax. Column names are written as $["name"] and are case-sensitive. You learn more in the expressions lesson.

And versus or

The most common filtering bug is mixing up AND and OR. "Customers from Spain and from Italy" is what people say, but a row cannot be both, so the filter must use OR.

Python Stand-in: AND versus OR

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.

Missing values in filters

A missing value is not zero, not an empty string, and not "false". A condition such as amount > 100 does not match a row whose amount is missing. If you then use the "exclude" side to collect everything else, rows with missing values may land in the group you did not expect. Always ask where missing values should go, and test with a row that has one.

SQL Stand-in: where do missing amounts go?

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

SQL puts the row with a missing amount in neither of the first two groups. KNIME has its own rules for missing values, so check them in your own workflow with a small test table.

Sorting and taking the top rows

The Sorter node orders rows by one or more columns. When you only need the largest or smallest few, Top k Row Filter does the sorting and trimming in one step, and is more efficient than sorting everything and filtering afterward. Watch for ties: when two rows share the same value at the cutoff, decide whether you accept an arbitrary pick or need a second sort column.

Splitting instead of discarding

Sometimes you want both parts: valid orders to analyze and invalid ones to report. A splitting node, or two filters with opposite conditions, can produce both outputs. Keeping the rejected rows gives you an audit trail.

Always compare row counts before and after a filter. If a filter removes 90% of rows and you expected 2%, stop and investigate. Add the counts to your labels or check them in the node monitor.

Text matching

Filters on text deserve extra care. "Contains an" matches Canada, Japan, and Ana alike, and case sensitivity may or may not apply, depending on your settings. Prefer exact matches when you know the full values. When you need patterns, use wildcards or regular expressions and test them against values that should match and values that should not. A list of the distinct values in a column, which you can get from a grouping node, shows you which spellings really exist.

Order of filtering

The position of a filter changes both speed and meaning. Filtering early reduces the data that later nodes must process. But some filters depend on calculated columns, and some should happen after a join. For example, if you filter customers by region before a left join from orders, orders for customers outside that region become unmatched rather than removed. Think about what each row represents at the point where you filter it.

Filter placement Effect
Before a join Smaller inputs, but may create unmatched rows
After a join Can use columns from both sides
Before grouping Changes which rows are summed
After grouping Removes whole groups, such as small ones

A quick audit pattern

For an important filter, keep three counts: rows in, rows kept, and rows removed. The kept and removed counts must add up to the input count. If you cannot produce both parts with one node, use a second filter with the opposite condition, then check the sum. With missing values, remember that "opposite" must also account for them.

Practice task

Make a table of ten rows with a numeric column that includes two missing values and values exactly equal to your threshold. Build filters for "greater than" and "at least", record the counts, and explain every difference. This five-minute test prevents many arguments later.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. You need customers from Spain or Italy. Which logic keeps them?

    One row has one country, so you need OR.
  2. 2. Which node efficiently keeps the ten largest values?

    Top k Row Filter combines ordering and trimming efficiently.
  3. 3. What should you check after filtering?

    Unexpected row counts reveal wrong conditions.

Summary

  • Drop unneeded columns early and check how new columns are treated.
  • Row Filter keeps or removes rows; Expression Row Filter handles complex rules.
  • Choose AND, OR, include, and exclude deliberately.
  • Decide where missing values should go and test it.
  • Compare row counts and keep rejected rows when you may need to explain them.

Next: Expressions and Calculated Columns

Tu progreso se guarda en este navegador. No necesitas una cuenta.