explode()
explode turns each item of a list-like cell into its own row.
In this page:
Syntax
df = df.explode("list_column")
explode()
When a cell holds a list, explode creates one row per element and repeats the other columns. The original index is repeated unless you call reset_index. It is the standard way to normalize tags or multi-valued fields.
Note:
Pair explode with str.split to expand comma-separated text.
Example: explode()
import pandas as pd
df = pd.DataFrame({"post": ["p1", "p2"], "tags": [["py", "data"], ["sql"]]})
print(df.explode("tags").reset_index(drop=True))
s = pd.Series(["a,b", "c"]).str.split(",")
print(s.explode())
# Output:
# post tags
# 0 p1 py
# 1 p1 data
# 2 p2 sql
# 0 a
# 0 b
# 1 c
# dtype: object
Related Topics
Common Mistakes
- Forgetting the index repeats
- Exploding non-list values
- Not planning for empty lists becoming NaN
Chapter Summary
- explode makes one row per list item
- Other columns are repeated
- Index repeats until reset
- Empty lists become NaN
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: