Exploding a list-like column with Pandas explode() method

Introduction to Pandas explode() and how to use it to reshape a Series or a DataFrame

B. Chen
5 min readMar 29, 2023
Photo by Sincerely Media on Unsplash

In the step of data pre-processing, we often need to prepare our data in specific ways before feeding it into a machine learning model. One of the examples is to transform list-like columns into rows. Pandas provides various methods for that, among them apply() and explode() are the two most popular methods.

Pandas explode() example

In this article, we’ll explore how to use the Pandas explode() method to unnest a list-like column. This article covers the following topics:

1. Basic usage
2. Series use cases
2.1 Other singular entries
2.2 Empty list
2.3 String with delimiter
3. DataFrame use cases
3.1 Other singular entries
3.2 Empty list
3.3 Multiple list-like columns
3.4 String with delimiter
4. explode() v.s. apply()
Conclusion

--

--