Skip to content
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

ENH: Multi-Column explode #39240

Closed
lschwetlick opened this issue Jan 17, 2021 · 1 comment · Fixed by #40770
Closed

ENH: Multi-Column explode #39240

lschwetlick opened this issue Jan 17, 2021 · 1 comment · Fixed by #40770
Labels
Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@lschwetlick
Copy link

lschwetlick commented Jan 17, 2021

Is your feature request related to a problem?

I have often looked for the option to use the explode function on multiple columns at the same time.

Example:

 A | B |    C   |    D
------------------------
 1 | a | [1,2] | [7,8]
 2 | b | [3,4] | [9,1]
 3 | c | [5,6] | [2,3]

===>

 A | B |    C  |   D
------------------
 1 | a |    1   |   7
 1 | a |    2   |  8
 2 | b |    3   |  9
 2 | b |    4   |   1
 3 | c |    5   |   2
 3 | c |    6   |   3

For obvious reasons exploding first one and then the other column will not yield the result we want here, because we will end up duplicating the values in the first explode during the second explode.

Describe the solution you'd like

Either it could be df.explode(["C","D"]) or it could be its own function df.multi_explode(["C","D"]). Both ways could use more or less the same method that the existing explode function uses.

API breaking implications

The only issue I see with this are cases where the lists in the C and D column aren't the same length, in which case we would need to pad them.

Context

I don't know if this has been discussed previously, but if there is interest in this a Pull request concerning this feature I could try to implement it.

@lschwetlick lschwetlick added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 17, 2021
@lschwetlick
Copy link
Author

It could be done something like this

@lithomas1 lithomas1 added Reshaping Concat, Merge/Join, Stack/Unstack, Explode and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 23, 2021
@iynehz iynehz mentioned this issue Apr 3, 2021
4 tasks
@jreback jreback added this to the 1.3 milestone Apr 7, 2021
@simonjayhawkins simonjayhawkins removed this from the 1.3 milestone Jun 11, 2021
iynehz added a commit to iynehz/pandas that referenced this issue Jun 16, 2021
iynehz added a commit to iynehz/pandas that referenced this issue Jun 17, 2021
iynehz added a commit to iynehz/pandas that referenced this issue Jun 17, 2021
@jreback jreback added this to the 1.3 milestone Jun 18, 2021
iynehz added a commit to iynehz/pandas that referenced this issue Jun 20, 2021
iynehz added a commit to iynehz/pandas that referenced this issue Jun 20, 2021
neinkeinkaffee pushed a commit to neinkeinkaffee/pandas that referenced this issue Jun 21, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this issue Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants