Skip to content

Commit 1904564

Browse files
Marco GorelliMarcoGorelli
Marco Gorelli
authored andcommitted
Remove special-casing multiindex
1 parent 06d1dc7 commit 1904564

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

pandas/core/frame.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6262,13 +6262,7 @@ def explode(self, column: Union[str, Tuple]) -> "DataFrame":
62626262
result = self.copy()
62636263
exploded_col = result.pop(column).reset_index(drop=True).explode()
62646264
result = result.reset_index().join(exploded_col)
6265-
6266-
if isinstance(self.index, ABCMultiIndex):
6267-
result.index = pandas.MultiIndex.from_frame(
6268-
result.iloc[:, : self.index.nlevels]
6269-
)
6270-
else:
6271-
result.index = result.iloc[:, 0]
6265+
result.set_index(result.columns[: self.index.nlevels].tolist(), inplace=True)
62726266
result.index.names = self.index.names
62736267
result = result.reindex(columns=self.columns, copy=False)
62746268

0 commit comments

Comments
 (0)