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

Add option to not sort within groups in GroupBy #595

Closed
wesm opened this issue Jan 9, 2012 · 5 comments
Closed

Add option to not sort within groups in GroupBy #595

wesm opened this issue Jan 9, 2012 · 5 comments
Milestone

Comments

@wesm
Copy link
Member

wesm commented Jan 9, 2012

No description provided.

@stig
Copy link

stig commented Jan 11, 2012

I'd love an option to maintain the column order that I've specified. At the moment I do this:

    print df.groupby('Status')['Duration'].agg({ 'Min': np.min,
                                                 'Max':np.max,
                                                 'Mean': np.mean,
                                                 'Median': np.median,
                                                 'Stddev':np.std,
                                                 })

but the column order come out like this:

         Max    Mean     Median  Min    Stddev
Error    0.141  0.09967  0.093   0.072  0.02796
Success  12.07  5.879    11.05   0.27   5.41

Which is not ideal. I'd love to pass an OrderedDict and have the order be respected.

    d = OrderedDict([('Min', np.min),
                     ('Max', np.max),
                     ('Mean', np.mean),
                     ('Median', np.median),
                     ('Stddev', np.std),
                     ])

... or, the method could just accept a list of tuples and respect that order.

@wesm
Copy link
Member Author

wesm commented Jan 11, 2012

@stig i'll open a separate issue for the thing you mention which I agree with

@soupault
Copy link
Contributor

@stig Hi, any news or plans on this issue?

@jreback
Copy link
Contributor

jreback commented Aug 13, 2015

pass sort=False

@soupault
Copy link
Contributor

@jreback brilliant, thanks a lot!

dan-nadler pushed a commit to dan-nadler/pandas that referenced this issue Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants