Split a Column by a Delimiter
A store list has a location field such as EU|Paris, and you want separate
region and city columns. Split Column cuts the text at a delimiter and
writes the pieces, in order, into the columns you name.
You'll use: File Input → Split Column → File Output.
- 1InputFile Inputstores.csv
- 2TransformSplit Columnlocation · | →
region, city - 3OutputFile Outputstores_split
Sample data
Save this as stores.csv. Store S3 has no city, S4 has no location, and
S5 has a third piece.
store_id,location
S1,EU|Paris
S2,US|Boston
S3,EU
S4,
S5,US|Austin|TXSteps
- On Datasets, upload
stores.csv. - In a new flow, add File Input. Set File type to CSV and Dataset
to
stores.csv. - Add Split Column and set:
- Column:
location. - Split by: Delimiter.
- Delimiter: click Pipe, or type
|. - New columns:
region, city. The first piece goes into the first name, the second piece into the second. - Leave Keep the original column checked, so you can compare each result with its source.
- Column:
- Add File Output. Set File type to CSV (.csv) and Dataset name to
stores_split. 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: "split the location column on | into region and city." 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
| store_id | location | region | city |
|---|---|---|---|
| S1 | EU|Paris | EU | Paris |
| S2 | US|Boston | US | Boston |
| S3 | EU | EU | null |
| S4 | null | null | null |
| S5 | US|Austin|TX | US | Austin |
Check the result
Save the flow, click Preview, select the Split Column node and click Run
preview. S1 should show EU and Paris. If region holds the whole
EU|Paris, the delimiter does not match the data, for example a comma instead
of a pipe.
Pitfalls
- Extra pieces are dropped.
TXinUS|Austin|TXhas no column, so it is not in the output. Add a third name to New columns to keep it, and keep the original column to spot such rows. - Missing pieces become null.
S3gets a nullcityrather than an error, so check for nulls before you rely on the new column. - Spaces stay.
EU | Parisgives"EU "and" Paris". Add a String Transform with Strip spaces on each new column. - Choose a delimiter that only separates. Splitting people's names on a space breaks names with several words.
- For one row per piece instead of one column per piece, use Split to Rows.
Exported Python
Click Export in the editor toolbar. The pandas and polars tabs show
this code for the flow. It reads stores.csv from the script's folder and
writes stores_split.csv.
import pandas as pd
df_stores = pd.read_csv('stores.csv')
_parts = df_stores['location'].astype('string').str.split('|', expand=True)
df_stores = df_stores.assign(region=(_parts[0] if 0 in _parts.columns else pd.NA), city=(_parts[1] if 1 in _parts.columns else pd.NA))
df_stores.to_csv('stores_split.csv', index=False)