Tutorials References Menu

Pandas DataFrame explode() Method

❮ DataFrame Reference


Example

Turn every element in the "Typ" column into a row:

import pandas as pd

data = {
  "Brand": ["Ford", "Ford", "Ford"],
  "Model": ["Sierra", "F-150", "Mustang"],
  "Typ" : ["2.0 GL", "Raptor", ["Mach-E", "Mach-1"]]
}
df = pd.DataFrame(data)

newdf = df.explode('Typ')
Try it Yourself »

Definition and Usage

The explode() method converts each element of the specified column(s) into a row.


Syntax

dataframe.explode(column, ignore_index)

Parameters

The parameter ignore_index is a keyword argument.

Parameter Value Description
column String
Tupl
Required. Specifies the column to explode
ignore_index True
False
Optional, default False. Specifies whether to ignore index or not. If True the original indexes are ignored, and replaced by 0, 1, 2 etc.

Return Value

A DataFrame with the exploded result.

This method does not change the original DataFrame.


❮ DataFrame Reference