Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add column_offset to explode #59238

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down