Skip to content

ENH: Explode multiple columns of DataFrame #28465

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

Closed
wants to merge 13 commits into from
Prev Previous commit
Next Next commit
ENH: DataFrame.explode() multiple columns
Now explode() can also take in a list of columns and explode them all, given that for every record in the dataframe the elements of the exploding columns all have the same length
  • Loading branch information
Kyle Stahl authored Sep 16, 2019
commit 6326745e18426bc6f07064b587e560834f9d6151
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6298,7 +6298,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