Skip to content

Commit

Permalink
Add column_offset to explode
Browse files Browse the repository at this point in the history
  • Loading branch information
ritwizsinha committed Jul 12, 2024
1 parent 69fe98d commit 133ab28
Showing 1 changed file with 10 additions and 1 deletion.
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

0 comments on commit 133ab28

Please sign in to comment.