Ciaren

Combine Columns with Fallback Values

Choose a primary email when it exists, otherwise use a backup email. Coalesce checks columns in order and copies the first non-null value into a new column.

You'll use: File Input → Coalesce Columns → File Output.

Steps

  1. Upload your CSV on Datasets and select it in File Input.
  2. Add Coalesce Columns with columns: ["primary_email", "backup_email"] and new_column: email.
  3. Leave keep_original: true to compare the source and result columns.
  4. Preview the node. A row with two missing values should still have null in email.
  5. Connect File Output, choose CSV, and run the flow.

Before / after

Exported Python

These runnable examples use the same configuration. The transformation lines come from Ciaren's code generators.

pandas

python
import pandas as pd

df_1 = pd.DataFrame({
    'primary_email': ['[email protected]', None, None, ''],
    'backup_email': ['[email protected]', '[email protected]', None, '[email protected]'],
})
df_2 = df_1.assign(email=lambda _d: _d['primary_email'].where(pd.notna, _d['backup_email']))
print(df_2)

Polars

python
import polars as pl

df_1 = pl.DataFrame({
    'primary_email': ['[email protected]', None, None, ''],
    'backup_email': ['[email protected]', '[email protected]', None, '[email protected]'],
})
df_2 = df_1.with_columns(pl.coalesce([pl.col('primary_email'), pl.col('backup_email')]).alias('email'))
print(df_2)

Tips

  • Put the most trusted column first. Coalesce does not compare or merge two non-null values.
  • An empty string is not null, so it takes priority over the backup. If empty text means missing in your source, normalize it to null first.
  • Set keep_original: false only after checking the output, to drop the source columns.
  • To join pieces of text together, use Combine Columns.

See also