.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.explode  #

DataFrame.  explode  (  _ column  _ , _ ignore_index  =  False  _ )  [
[source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/frame.py#L9735-L9861) #

    

Transform each element of a list-like to a row, replicating index values.

Parameters  :

    

**column** IndexLabel

    

Column(s) to explode. For multiple columns, specify a non-empty list with each
element be str or tuple, and all specified columns their list-like data on
same row of the frame must have matching length.

New in version 1.3.0:  Multi-column explode

**ignore_index** bool, default False

    

If True, the resulting index will be labeled 0, 1, â¦, n - 1.

Returns  :

    

DataFrame

    

Exploded lists to rows of the subset columns; index will be duplicated for
these rows.

Raises  :

    

ValueError

    

  * If columns of the frame are not unique. 

  * If specified columns to explode is empty list. 

  * If specified columns to explode have not matching count of elements rowwise in the frame. 

See also

[ ` DataFrame.unstack  `
](pandas.DataFrame.unstack.html#pandas.DataFrame.unstack
"pandas.DataFrame.unstack")

    

Pivot a level of the (necessarily hierarchical) index labels.

[ ` DataFrame.melt  ` ](pandas.DataFrame.melt.html#pandas.DataFrame.melt
"pandas.DataFrame.melt")

    

Unpivot a DataFrame from wide format to long format.

[ ` Series.explode  ` ](pandas.Series.explode.html#pandas.Series.explode
"pandas.Series.explode")

    

Explode a DataFrame from list-like columns to long format.

Notes

This routine will explode list-likes including lists, tuples, sets, Series,
and np.ndarray. The result dtype of the subset rows will be object. Scalars
will be returned unchanged, and empty list-likes will result in a np.nan for
that row. In addition, the ordering of rows in the output will be non-
deterministic when exploding sets.

Reference [ the user guide  ](../../user_guide/reshaping.html#reshaping-
explode) for more examples.

Examples

    
    
    >>> df = pd.DataFrame({'A': [[0, 1, 2], 'foo', [], [3, 4]],
    ...                    'B': 1,
    ...                    'C': [['a', 'b', 'c'], np.nan, [], ['d', 'e']]})
    >>> df
               A  B          C
    0  [0, 1, 2]  1  [a, b, c]
    1        foo  1        NaN
    2         []  1         []
    3     [3, 4]  1     [d, e]
    

Single-column explode.

    
    
    >>> df.explode('A')
         A  B          C
    0    0  1  [a, b, c]
    0    1  1  [a, b, c]
    0    2  1  [a, b, c]
    1  foo  1        NaN
    2  NaN  1         []
    3    3  1     [d, e]
    3    4  1     [d, e]
    

Multi-column explode.

    
    
    >>> df.explode(list('AC'))
         A  B    C
    0    0  1    a
    0    1  1    b
    0    2  1    c
    1  foo  1  NaN
    2  NaN  1  NaN
    3    3  1    d
    3    4  1    e
    

[ __ previous  pandas.DataFrame.melt  ](pandas.DataFrame.melt.html "previous
page") [ next  pandas.DataFrame.squeeze  __ ](pandas.DataFrame.squeeze.html
"next page")

__ On this page

  * ` DataFrame.explode()  `

[ __ Show Source
](../../_sources/reference/api/pandas.DataFrame.explode.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.