Skip to content

Commit 63f2d47

Browse files
Marco GorelliMarcoGorelli
Marco Gorelli
authored andcommitted
Re-write in more readable way
1 parent 0b86a55 commit 63f2d47

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

pandas/core/frame.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6259,12 +6259,9 @@ def explode(self, column: Union[str, Tuple]) -> "DataFrame":
62596259
if not self.columns.is_unique:
62606260
raise ValueError("columns must be unique")
62616261

6262-
column_with_index = self[column].reset_index()
6263-
result = (
6264-
self.drop([column], axis=1)
6265-
.reset_index()
6266-
.join(column_with_index[column].explode())
6267-
)
6262+
frame = self.copy()
6263+
exploded_col = frame.pop(column).reset_index(drop=True).explode()
6264+
result = frame.reset_index().join(exploded_col)
62686265

62696266
if isinstance(self.index, MultiIndex):
62706267
result.index = pandas.MultiIndex.from_frame(

0 commit comments

Comments
 (0)