Fill Missing Values
A survey export has empty cells in age and region, and you want to keep
every respondent instead of dropping rows. Use one Fill Nulls node per
column group: the median for age, the text Unknown for region.
You'll use: File Input → Fill Nulls → Fill Nulls → File Output.
- 1InputFile Inputsurvey.csv
- 2CleanFill Nullsage →
median - 3CleanFill Nullsregion →
Unknown - 4OutputFile Outputsurvey_filled
Sample data
Save this as survey.csv. Respondent 2 has no age and respondent 3 has no
region. An empty cell in a CSV is read as null.
respondent_id,age,region
1,25,North
2,,South
3,40,
4,31,East
5,95,NorthSteps
- On Datasets, upload
survey.csv. - In a new flow, add File Input. Set File type to CSV and Dataset
to
survey.csv. - Add Fill Nulls. Set Strategy to Median and Columns (optional) to
age. - Add a second Fill Nulls. Set Strategy to Constant value, Fill
value to
Unknown, and Columns (optional) toregion. Each node has one strategy, so a second column that needs a different fill needs a second node. - Add File Output. Set File type to CSV (.csv) and Dataset name to
survey_filled. Connect the nodes in order and click Run.
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: "fill missing numbers with the column median and missing text with Unknown." 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.
Result
| respondent_id | age | region |
|---|---|---|
| 1 | 25.0 | North |
| 2 | 35.5 | South |
| 3 | 40.0 | Unknown |
| 4 | 31.0 | East |
| 5 | 95.0 | North |
The median of 25, 31, 40 and 95 is 35.5. The filled value is a decimal, so the
whole age column is written with decimals.
Choose the strategy
- Median is the safer default for numbers with outliers. On this sample the mean would fill 47.75, older than three of the four known ages.
- Mean (average), Minimum, Maximum and Zero also fill numeric columns. Most frequent (mode) works for text too.
- Forward fill copies the value from the row above, Backward fill from
the row below. Use them only on data in a meaningful order, such as a time
series sorted by date. On this sample, forward fill would give respondent 3
the region
Southfrom respondent 2.
Check the result
Save the flow, click Preview, select the second Fill Nulls node and click
Run preview. Respondent 2 should show age 35.5 and respondent 3 region
Unknown. Switch to Profile: the null count for age and region should
be 0.
Pitfalls
- Set the columns. With Columns (optional) empty, a constant like
Unknowngoes into every text column that has a null, not onlyregion. Columns whose type the value doesn't fit are skipped:Unknownleaves the numericagealone, while0fillsageand the text columns alike. - A space is not missing. A cell that contains only spaces is text, not null, so Fill Nulls leaves it alone. Fix such cells in the source file, where an empty cell is read as null.
- Filling before training a model computes the median on all rows, including the rows you later test on. For modeling, use the train node's Advanced → Preprocessing options instead, see Feature Engineering.
- To drop the rows instead, use Drop Nulls.
Exported Python
Click Export in the editor toolbar. The pandas and polars tabs show
this code for the flow. It reads survey.csv from the script's folder and
writes survey_filled.csv.
import pandas as pd
df_survey = pd.read_csv('survey.csv')
df_survey = df_survey.fillna({'age': df_survey['age'].median()})
df_survey = df_survey.copy()
for _col in ['region']:
try:
_fill = pd.array(['Unknown'], dtype=df_survey[_col].dtype)[0]
except (ValueError, TypeError):
continue # the value does not fit this column's type
df_survey[_col] = df_survey[_col].fillna(_fill)
df_survey.to_csv('survey_filled.csv', index=False)