Skip to content

Data Quality Checks

A contact export has stray spaces, mixed-case emails, a non-numeric age, a duplicate person, an impossible age and a row with no name. This flow fixes what can be fixed, drops what cannot, and leaves two trustworthy rows. The order of the steps matters, and the figure below shows why.

You'll use: File Input → String Transform (three times) → Change Types → Drop Nulls → Remove Duplicates → Filter Rows → File Output.

  1. Input
    File Input
    contacts.csv
  2. Clean
    String Transform
    name: strip whitespace
  3. Clean
    String Transform
    email: strip whitespace
  4. Clean
    String Transform
    email: lowercase
  5. Clean
    Change Types
    age → integer, bad values → null
  6. Clean
    Drop Nulls
    subset: name, age
  7. Clean
    Remove Duplicates
    subset: email · keep: first
  8. Clean
    Filter Rows
    age between 0 and 120
  9. Output
    File Output
    contacts_clean.csv

Sample data

Save this as contacts.csv, or download contacts.csv, and upload it on the Datasets page:

csv
name,email,age
  Ada Lovelace ,[email protected],36
Grace Hopper,[email protected],unknown
Grace Hopper,[email protected],85
Linus T,[email protected] ,250
,[email protected],40

What is wrong with each row:

RowProblem
AdaSpaces around the name, uppercase email
Grace (1st)Age is the text unknown
Grace (2nd)Same person as the first Grace, email in uppercase
LinusTrailing space in the email, age 250
(no name)Empty name

Build the flow

  1. File Input: File type CSV, dataset contacts.csv.
  2. String Transform: Column name, Operation Strip spaces.
  3. String Transform: Column email, Operation Strip spaces.
  4. String Transform: Column email, Operation Lowercase. After steps 3 and 4, [email protected] and [email protected] are the same string, so the duplicate check in step 7 can see them.
  5. Change Types: under Casts, set age → integer. Set On bad values to Set to null (coerce). unknown becomes null instead of stopping the run.
  6. Drop Nulls: Subset = name, age. This removes the row with no name (an empty CSV cell reads as null) and the first Grace, whose age is now null.
  7. Remove Duplicates: Subset = email, Keep first occurrence. Only one [email protected] row is left by now, so nothing else is removed here on this sample; on real data, this is where repeats of the same person go.
  8. Filter Rows: Column age, Operator between (range), From 0, To 120. Both bounds are inclusive. This drops Linus's age of 250.
  9. File Output: File type CSV, Dataset name contacts_clean.

Select steps 5 to 8 one at a time and read the preview to see each rule remove exactly the row you expect.

Prefer to describe it?

With a provider key set up, upload the sample data, open a blank flow in the same project and ask the Flow assistant, for example: "strip and lowercase the text columns, turn age into an integer, drop rows with no name or age, remove duplicate emails and keep ages from 0 to 120." Review the proposed nodes and settings, then choose Apply and save. We ran this prompt on the sample data; see what the assistant built. Its flow can differ from the steps above in node order and names, so check each setting. The assistant never runs a flow, so click Run yourself.

Why Drop Nulls comes before Remove Duplicates

Both Grace rows share an email. Keep first occurrence keeps whichever comes first, and the first one is the copy with the unusable age. If you remove duplicates before you drop nulls, that bad copy wins, the good copy is discarded, and Drop Nulls then removes the bad copy too. Grace disappears from the output.

Removing duplicates first keeps the Grace row with a null age, which Drop Nulls then deletes; dropping nulls first leaves the Grace row with age 85

The same logic applies to the String Transform steps: lowercase before you deduplicate, or [email protected] and [email protected] count as two people.

Result

Full flow
Before
nameemailage
Ada Lovelace [email protected]36
Grace Hopper[email protected]unknown
Grace Hopper[email protected]85
Linus T[email protected] 250
null[email protected]40
5 rows · 3 cols
After
namenewemailnewagenew
Ada Lovelace[email protected]36
Grace Hopper[email protected]85
2 rows · 3 cols

Check the result

  • Two rows: Ada Lovelace, 36, and Grace Hopper, 85.
  • [email protected] is lowercase and Ada Lovelace has no leading space.
  • The preview of Change Types shows age as an integer column with one empty cell, for the first Grace.

If Grace is missing, Remove Duplicates runs before Drop Nulls. If Ada's email is still [email protected], the Lowercase step is missing or set on the wrong column.

Exported Python

Click Export in the editor toolbar and open the pandas tab. The _filter_value helper at the top compares the Filter Rows bounds, saved as the text '0' and '120', as numbers because age is numeric:

python
import pandas as pd

def _filter_value(df, column, value):
    """Type a comparison value like its column: text becomes a number on a numeric column."""
    if isinstance(value, list):
        items = [_filter_value(df, column, v) for v in value]
        # One float makes every item a float: polars types a list by its first item.
        return [float(v) for v in items] if any(isinstance(v, float) for v in items) else items
    numeric = pd.api.types.is_numeric_dtype(df[column]) and not pd.api.types.is_bool_dtype(df[column])
    if not isinstance(value, str) or not numeric:
        return value
    try:
        return int(value)
    except ValueError:
        pass
    try:
        return float(value)
    except ValueError:
        raise ValueError(f"Value {value!r} is not a number, but column {column!r} is numeric.") from None

df_contacts = pd.read_csv('contacts.csv')

df_contacts = (
    df_contacts.assign(name=lambda _d: _d['name'].astype('string').str.strip())
    .assign(email=lambda _d: _d['email'].astype('string').str.strip())
    .assign(email=lambda _d: _d['email'].astype('string').str.lower())
    .assign(age=lambda _d: pd.to_numeric(_d['age'], errors='coerce').astype('Int64'))
    .dropna(subset=['name', 'age'])
    .drop_duplicates(subset='email')
    .loc[lambda _d: _d['age'].between(_filter_value(_d, 'age', '0'), _filter_value(_d, 'age', '120'))]
)

df_contacts.to_csv('contacts_clean.csv', index=False)

Run it next to contacts.csv and contacts_clean.csv holds the same two rows. Int64 (capital I) is pandas' nullable integer type: it can hold the null that errors='coerce' produces, which plain int64 cannot. The polars tab writes the same rows.

Pitfalls

  • Coerce hides bad values. Set to null (coerce) turns anything unparseable into null without an error. Here Drop Nulls removes those rows right after, so check the Change Types preview to see how many there were.
  • Drop Nulls with an empty subset checks every column. Set the subset to the columns that must be present; a missing optional column should not cost you the row.
  • Remove Duplicates without a subset compares whole rows. The two Graces differ in age, so they would both survive.

Going further

  • Fail instead of filtering. Replace Filter Rows with Assert Value Range (Column age, Min 0, Max 120, On violation Error (stop run)) when an impossible age should stop the pipeline rather than disappear quietly.
  • Check email format. Add a Filter Rows with Operator contains (text) and Value @.
  • Keep the table fresh. Schedule the flow to rerun on each new export.

Next steps