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.
- InputFile Inputcontacts.csv
- CleanString Transformname: strip whitespace
- CleanString Transformemail: strip whitespace
- CleanString Transformemail: lowercase
- CleanChange Typesage →
integer, bad values → null - CleanDrop Nullssubset: name, age
- CleanRemove Duplicatessubset: email · keep: first
- CleanFilter Rowsage between 0 and 120
- OutputFile Outputcontacts_clean.csv
Sample data
Save this as contacts.csv, or download contacts.csv,
and upload it on the Datasets page:
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],40What is wrong with each row:
| Row | Problem |
|---|---|
| Ada | Spaces around the name, uppercase email |
| Grace (1st) | Age is the text unknown |
| Grace (2nd) | Same person as the first Grace, email in uppercase |
| Linus | Trailing space in the email, age 250 |
| (no name) | Empty name |
Build the flow
- File Input: File type CSV, dataset
contacts.csv. - String Transform: Column
name, Operation Strip spaces. - String Transform: Column
email, Operation Strip spaces. - 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. - Change Types: under Casts, set
age→integer. Set On bad values to Set to null (coerce).unknownbecomes null instead of stopping the run. - 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. - 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. - Filter Rows: Column
age, Operator between (range), From0, To120. Both bounds are inclusive. This drops Linus's age of 250. - 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.
The same logic applies to the String Transform steps: lowercase before you
deduplicate, or [email protected] and [email protected] count as two people.
Result
| name | age | |
|---|---|---|
| Ada Lovelace | [email protected] | 36 |
| Grace Hopper | [email protected] | unknown |
| Grace Hopper | [email protected] | 85 |
| Linus T | [email protected] | 250 |
| null | [email protected] | 40 |
| namenew | emailnew | agenew |
|---|---|---|
| Ada Lovelace | [email protected] | 36 |
| Grace Hopper | [email protected] | 85 |
Check the result
- Two rows: Ada Lovelace, 36, and Grace Hopper, 85.
[email protected]is lowercase andAda Lovelacehas no leading space.- The preview of Change Types shows
ageas 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:
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, Min0, Max120, 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.