If you’ve tried str.split() on a pandas column with a comma delimiter, you’ve probably seen a column of lists instead of new columns. Pass expand=True and the pieces land in separate columns.
In this tutorial, I’ll show you five ways to handle a pandas split column by delimiter task on one small orders table. Results came from Python 3.12.5 and pandas 3.0.6.
The sample orders DataFrame we’ll use for splitting
A Seattle coffee roaster’s orders pack the address and basket into text columns. Every example imports this file:
# Online orders for a Seattle coffee roaster, 01/12/2026
import pandas as pd
orders = pd.DataFrame({
"order_id": [1041, 1042, 1043, 1044],
"customer": ["Megan Brooks", "Mary Ann Lopez", "Tyler Ramirez",
"Ava Chen"],
"ship_to": ["Austin, TX, 78701", "Denver, CO, 80202",
"Miami, FL, 33101", "Portland, OR"],
"items": ["coffee|mug|filters", "tea", "coffee;beans", "coffee | mug"],
"total": [42.50, 12.99, 31.75, 27.00],
})
Mary Ann Lopez has a three-word name, Portland has no ZIP, and items mixes |, ; and spaces.
Data in a file? Reading a CSV with pandas gets you here.
Method 1: Split a column into multiple columns with str.split(expand=True) (Recommended)
Use this when every row has the same delimiter, like the comma-space in ship_to:
from orders import orders
print(orders["ship_to"].str.split(", ").head(2)) # lists, not columns
parts = orders["ship_to"].str.split(", ", expand=True)
print(parts)
print(parts.dtypes.astype(str).tolist())
orders[["city", "state", "zip"]] = parts
print(orders[["customer", "city", "state", "zip"]])
Output:
0 [Austin, TX, 78701]
1 [Denver, CO, 80202]
Name: ship_to, dtype: object
0 1 2
0 Austin TX 78701
1 Denver CO 80202
2 Miami FL 33101
3 Portland OR NaN
['str', 'str', 'str']
customer city state zip
0 Megan Brooks Austin TX 78701
1 Mary Ann Lopez Denver CO 80202
2 Tyler Ramirez Miami FL 33101
3 Ava Chen Portland OR NaN
The first print shows lists. With expand=True, you get three columns, and Portland’s missing ZIP becomes NaN.

How does this code work?
expand=True returns one column per piece, numbered 0 to 2. Assigning to orders[["city", "state", "zip"]] names them; see setting column names in pandas to rename later.
Note: on pandas 3.0, the new columns use the str dtype, so ZIPs stay text with leading zeros intact.
So here’s the catch: split on "," alone and later pieces keep a leading space, like ' TX'.
Method 2: Limit the splits with n and str.rsplit()
Names break when you split on every space. Same table, customer column:
from orders import orders
names = orders["customer"]
print(names.str.split(" ", n=1, expand=True)) # first word | rest
print(names.str.rsplit(" ", n=1, expand=True)) # rest | last word
zips = orders["ship_to"].str.rsplit(", ", n=1).str[-1]
print(zips.tolist()) # last field
Output:
0 1
0 Megan Brooks
1 Mary Ann Lopez
2 Tyler Ramirez
3 Ava Chen
0 1
0 Megan Brooks
1 Mary Ann Lopez
2 Tyler Ramirez
3 Ava Chen
['78701', '80202', '33101', 'OR']
n=1 gives “Mary” and “Ann Lopez”; rsplit gives “Mary Ann” and “Lopez”, which is what you want for last names.

How does this code work?
n caps the number of cuts; rsplit counts from the right, so n=1 isolates the last word. Plain strings work the same way, as in splitting a string by comma in Python.
Important: Portland has no ZIP, so its last piece is OR. Method 4 fixes that.
Method 3: Split a pandas column on multiple delimiters with regex
When rows use different separators, "|" alone would leave coffee;beans whole. Use a pattern on items:
from orders import orders
pattern = r"\s*[|;]\s*" # | or ; plus spaces
items = orders["items"].str.split(pattern, expand=True, regex=True)
print(items)
Output:
0 1 2
0 coffee mug filters
1 tea NaN NaN
2 coffee beans NaN
3 coffee mug NaN
Every row splits cleanly, and the spaces in coffee | mug are gone.

How does this code work?
\s*[|;]\s* means “a pipe or semicolon, with any spaces around it”. Setting regex=True makes the intent explicit.
Without it, pandas reads a one-character pattern literally and longer ones as regex. Pattern syntax is in splitting a string with regex in Python.
Method 4: Extract named columns with str.extract()
Use str.extract() when parts follow a pattern, not a fixed count. Same ship_to column, ZIP optional:
from orders import orders
pattern = r"(?P<city>[^,]+), (?P<state>[A-Z]{2})(?:, (?P<zip>\d{5}))?"
geo = orders["ship_to"].str.extract(pattern)
print(geo)
Output:
city state zip
0 Austin TX 78701
1 Denver CO 80202
2 Miami FL 33101
3 Portland OR NaN
Each named group becomes a column: city, state and zip. Portland gets NaN for zip instead of a wrong “OR”.

How does this code work?
(?P<city>...) names a group, and (?:, ...)? makes the ZIP optional. Rows that don’t match come back all NaN. To tally results, see counting unique values in a pandas column.
Method 5: Split a column into rows with explode()
To count items sold, you want one row per value, not more columns. Same items column:
from orders import orders
lists = orders["items"].str.split(r"\s*[|;]\s*", regex=True)
rows = orders.assign(item=lists).explode("item", ignore_index=True)
print(rows[["order_id", "item", "total"]])
print(rows["item"].value_counts().to_dict())
print(f"Orders total: ${orders['total'].sum():,.2f}")
print(f"Exploded total: ${rows['total'].sum():,.2f}") # double counts
Output:
order_id item total
0 1041 coffee 42.50
1 1041 mug 42.50
2 1041 filters 42.50
3 1042 tea 12.99
4 1043 coffee 31.75
5 1043 beans 31.75
6 1044 coffee 27.00
7 1044 mug 27.00
{'coffee': 3, 'mug': 2, 'filters': 1, 'tea': 1, 'beans': 1}
Orders total: $114.24
Exploded total: $257.99
Coffee appears 3 times and mug twice. But totals repeat, so the sum jumps from $114.24 to $257.99.

How does this code work?
str.split() returns lists, and explode() makes each element a row; ignore_index=True renumbers them. To go the other way, see merging two columns in pandas.
Pro Tip: sum money on the original DataFrame; count on the exploded one.
Which pandas split method should you use?
| Method | Use it when | Watch out for |
|---|---|---|
str.split(sep, expand=True) | Same delimiter in every row | Leading spaces |
str.rsplit(sep, n=1) | Last word or last field | Missing fields |
str.split(pattern, regex=True) | Mixed delimiters | Regex escaping |
str.extract(pattern) | Parts follow a pattern | NaN on no match |
str.split() + explode() | One row per value | Repeated totals |
I’d start with expand=True and switch to str.extract() once rows have optional parts.
Things to keep in mind when splitting pandas columns
- Strip whitespace. Split on
", "or callstr.strip()on each new column. - Match the names. Three pieces into two names raises
ValueError: Columns must be same length as key; selectparts[[0, 1]]or usen=1. - Convert types after. Split columns are text; see changing a column datatype in pandas.
Want more pandas column work? These come next:
- Add a column to a pandas DataFrame
- Replace values in a pandas column
- Delete columns from a pandas DataFrame
- Convert a string column to datetime in pandas
Frequently asked questions
How do I split a column by delimiter in pandas?
Use df["col"].str.split(",", expand=True) and assign it to new column names.
Why does str.split() return lists instead of columns?
expand defaults to False, which keeps each result as a list in one cell.
How do I split only on the first or last delimiter?
Use str.split(sep, n=1) for the first one and str.rsplit(sep, n=1) for the last.
Can pandas split a column on more than one delimiter?
Yes. Pass a regex such as r"[|;]" with regex=True.
How do I split a column into rows instead of columns?
Split without expand to get lists, then call df.explode("col").
Where is Series.str.split documented?
See Series.str.split() in the pandas docs.

Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn