diff --git a/pandas/core/series.py b/pandas/core/series.py index a22cc59b62499..306c681008437 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4083,7 +4083,9 @@ def reorder_levels(self, order: Sequence[Level]) -> Series: result.index = result.index.reorder_levels(order) return result - def explode(self, ignore_index: bool = False) -> Series: + def explode( + self, ignore_index: bool = False, column_offset: bool = False + ) -> Series: """ Transform each element of a list-like to a row. @@ -4092,6 +4094,9 @@ def explode(self, ignore_index: bool = False) -> Series: ignore_index : bool, default False If True, the resulting index will be labeled 0, 1, …, n - 1. + column_offset : bool, default False + If True, the resulting index will be labeled row offset with column offset. + Returns ------- Series @@ -4149,6 +4154,10 @@ def explode(self, ignore_index: bool = False) -> Series: else: index = self.index.repeat(counts) + if column_offset: + columns = [item for count in counts for item in range(count)] + index = MultiIndex.from_arrays([index, columns]) + return self._constructor(values, index=index, name=self.name, copy=False) def unstack(