Skip to content

Commit f8ce5e3

Browse files
author
Marco Gorelli
committed
Re-write in more readable way
1 parent e799c42 commit f8ce5e3

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
@@ -6244,12 +6244,9 @@ def explode(self, column: Union[str, Tuple]) -> "DataFrame":
62446244
if not self.columns.is_unique:
62456245
raise ValueError("columns must be unique")
62466246

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

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

0 commit comments

Comments
 (0)