Split or explode a column of dictionaries into separate columns with pandas
Codemia Knowledge Hub ·
To turn a pandas column of dictionaries into one column per key, normalize the column with pd.json_normalize() and join the result back to the original frame, dropping the original column.
Basic pattern with json_normalize
Suppose each row of a details column holds a dictionary:
Output:
pd.json_normalize() is usually the best option because it is explicit and copes well if the dictionaries become more nested later. Remember to drop the original column, or the frame keeps duplicated information.
apply(pd.Series) for flat dictionaries
For shallow dictionaries you will often see:
It is readable and fine for simple cases, but json_normalize is more flexible once nested fields appear.
Missing keys become NaN
Keys do not have to match across rows. Pandas aligns by key name and fills gaps with NaN:
That is normal and usually what you want, not a sign that pandas failed. Clean the gaps afterward if needed:
Parse JSON strings first
Sometimes the column looks like dictionaries but actually holds strings:
Without parsing, pandas treats the values as plain strings and cannot split them into columns.
Dictionary columns versus list columns
Despite the word "explode," explode() is for list-like values, not dictionaries. Calling it on a dictionary column is the most common mistake. Use:
json_normalizeorapply(pd.Series)for a column of dictionariesexplode()for a column of lists
A column of lists of dictionaries needs both steps:
Renaming dotted columns from nested dictionaries
With nested dictionaries, json_normalize produces dotted names such as address.city. That is often useful, but you can rename them:
Clean column names early so later analysis stays readable.
Related reading
- Split a dataset created by Tensorflow dataset API in to Train and Test?
- Split a large pandas dataframe
- Split a Pandas column of lists into multiple columns
- Split data directory into training and test directory with sub directory structure preserved
- Split a binary search Tree
- Split a List into smaller lists of N size
- Split a python list into other sublists i.e smaller lists
- Split a string by a delimiter in Python
System design interview problems on this topic
- Design a Web Crawler: solution and walkthrough
- Design a Task Scheduler: solution and walkthrough
- Design a URL Shortener (TinyURL): solution and walkthrough
- Design an API Rate Limiter: solution and walkthrough

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.