Skip to content

ENH: add optional sort_order keyword to concat(). #41016

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
DriesSchaumont opened this issue Apr 18, 2021 · 3 comments
Closed

ENH: add optional sort_order keyword to concat(). #41016

DriesSchaumont opened this issue Apr 18, 2021 · 3 comments
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@DriesSchaumont
Copy link
Member

DriesSchaumont commented Apr 18, 2021

Is your feature request related to a problem?

xref #33634

ser1 = pd.Series(["1","3"], index=pd.Index(["a", "c"], dtype="object"), dtype="object", name="test1")
ser2 = pd.Series([3, 4, 5], index=pd.Index(["a", "b", "c"], dtype="object"), dtype="float64", name="test2")
ser3 = pd.Series([6,7,8], index=pd.Index(["a", "b", "c"], dtype="object"), dtype="float64", name="test3")
pd.concat([ser1, ser2, ser3], axis=1, sort=False, keys=["test1", "test2", "test3"])
  test1  test2  test3
a     1    3.0    6.0
c     3    5.0    8.0
b   NaN    4.0    7.0

When concatenating, concat uses the index from the first series to determine the order of the non-concatenated axis.
It would be neat to have a way specify this order with either a function or a list. Currently, sort=True can be used, but it only allows for sorting.

Describe the solution you'd like

The solution could be either to:

  • add a new argument
  • expand the sort argument to take functions or lists
  • use the key argument for this.

API breaking implications

I think this change can be backward compatible

Describe alternatives you've considered

As an alternative, reindexing could be used. But this requires the extraction of the largest index first.

@DriesSchaumont DriesSchaumont added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 18, 2021
@jreback
Copy link
Contributor

jreback commented Apr 18, 2021

we already have .reindex
-1 on additional keywords

@rhshadrach
Copy link
Member

-1 as well, I think of combining frames and sorting the index/values are two different operations, it would involve too much complexity combining both into one.

@rhshadrach rhshadrach added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Apr 20, 2021
@jreback
Copy link
Contributor

jreback commented Apr 20, 2021

this request is similar to the join_axes argument which was deprecated and removed

this is easily accomplished by a reindex

@jreback jreback added this to the No action milestone Apr 20, 2021
@jreback jreback closed this as completed Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

3 participants