Skip to content

ENH: DataFrame.explode() multiple columns #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6207,14 +6207,15 @@ def stack(self, level=-1, dropna=True):

def explode(self, columns: Union[str, List[str]]) -> "DataFrame":
"""
Transform each element of a list-like to a row, replicating the index values.
Transform each element of a list-like to a row, replicating index values.

.. versionadded:: 0.25.0

Parameters
----------
column : str or tuple

columns : str or list
the column(s) to be exploded

Returns
-------
DataFrame
Expand Down Expand Up @@ -6298,7 +6299,7 @@ def explode(self, columns: Union[str, List[str]]) -> "DataFrame":
lengths_equal = []

for row in self[columns].iterrows():
# converts non-lists into 1 element lists
# converts non-lists into 1 element lists so len() is valid
r=row[1].apply(lambda x: x if type(x) in (list,tuple) else [x])

# make sure all lists in the same record are the same length
Expand Down