Skip to content

Commit 0f75eb3

Browse files
author
Marco Gorelli
committed
Re-write in more readable way
1 parent 566a7d2 commit 0f75eb3

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

pandas/core/frame.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -6243,12 +6243,9 @@ def explode(self, column: Union[str, Tuple]) -> "DataFrame":
62436243
if not self.columns.is_unique:
62446244
raise ValueError("columns must be unique")
62456245

6246-
column_with_index = self[column].reset_index()
6247-
result = (
6248-
self.drop([column], axis=1)
6249-
.reset_index()
6250-
.join(column_with_index[column].explode())
6251-
)
6246+
frame = self.copy()
6247+
exploded_col = frame.pop(column).reset_index(drop=True).explode()
6248+
result = frame.reset_index().join(exploded_col)
62526249

62536250
if isinstance(self.index, MultiIndex):
62546251
result.index = pandas.MultiIndex.from_frame(

0 commit comments

Comments
 (0)