explode(self, column: 'IndexLabel', ignore_index: 'bool' = False) -> 'DataFrame'
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 <reshaping.explode>
for more examples.
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.
Multi-column explode
If True, the resulting index will be labeled 0, 1, …, n - 1.
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.
Exploded lists to rows of the subset columns; index will be duplicated for these rows.
Transform each element of a list-like to a row, replicating index values.
DataFrame.melt
Unpivot a DataFrame from wide format to long format.
DataFrame.unstack
Pivot a level of the (necessarily hierarchical) index labels.
Series.explode
Explode a DataFrame from list-like columns to long format.
>>> 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.
This example is valid syntax, but we were not able to check execution>>> 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.
This example is valid syntax, but we were not able to check execution>>> 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 eSee :
The following pages refer to to this document either explicitly or contain code examples using this.
pandas.core.reshape.melt.melt
pandas.core.frame.DataFrame.melt
pandas.core.series.Series.explode
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them