Skip to content

Commit 133ab28

Browse files
committed
Add column_offset to explode
1 parent 69fe98d commit 133ab28

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pandas/core/series.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4083,7 +4083,9 @@ def reorder_levels(self, order: Sequence[Level]) -> Series:
40834083
result.index = result.index.reorder_levels(order)
40844084
return result
40854085

4086-
def explode(self, ignore_index: bool = False) -> Series:
4086+
def explode(
4087+
self, ignore_index: bool = False, column_offset: bool = False
4088+
) -> Series:
40874089
"""
40884090
Transform each element of a list-like to a row.
40894091
@@ -4092,6 +4094,9 @@ def explode(self, ignore_index: bool = False) -> Series:
40924094
ignore_index : bool, default False
40934095
If True, the resulting index will be labeled 0, 1, …, n - 1.
40944096
4097+
column_offset : bool, default False
4098+
If True, the resulting index will be labeled row offset with column offset.
4099+
40954100
Returns
40964101
-------
40974102
Series
@@ -4149,6 +4154,10 @@ def explode(self, ignore_index: bool = False) -> Series:
41494154
else:
41504155
index = self.index.repeat(counts)
41514156

4157+
if column_offset:
4158+
columns = [item for count in counts for item in range(count)]
4159+
index = MultiIndex.from_arrays([index, columns])
4160+
41524161
return self._constructor(values, index=index, name=self.name, copy=False)
41534162

41544163
def unstack(

0 commit comments

Comments
 (0)