Skip to content

Groupby filter changes ordering #4621

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
hayd opened this issue Aug 21, 2013 · 9 comments
Closed

Groupby filter changes ordering #4621

hayd opened this issue Aug 21, 2013 · 9 comments
Milestone

Comments

@hayd
Copy link
Contributor

hayd commented Aug 21, 2013

At the moment filter reorders wrt the groups.

Example:

In [1]: data = pd.DataFrame(
    {'pid' : [1,1,1,2,2,3,3,3],
     'tag' : [23,45,62,24,45,34,25,62],
     })

In [2]: g = data.groupby('tag')

In [3]: g.filter(lambda x: len(x) > 1)
Out[3]: 
   pid  tag
1    1   45
4    2   45
2    1   62
7    3   62

If there is a way to efficiently keep the order that would be ideal I think, failing that sort back afterwards (but being wary of sorting with dupe/unordered indexes).

cc #3680

@jtratner
Copy link
Contributor

@hayd What should it output instead?

@hayd
Copy link
Contributor Author

hayd commented Aug 22, 2013

Basically:

In [12]: g.filter(lambda x: len(x) > 1, dropna=False).dropna()
Out[12]:
   pid  tag
1    1   45
2    1   62
4    2   45
7    3   62

@jreback suggested in #3680 could be more efficient way...

@jreback
Copy link
Contributor

jreback commented Sep 27, 2013

cc @danielballan can you have a look?

@danielballan
Copy link
Contributor

On it.

@jreback
Copy link
Contributor

jreback commented Oct 2, 2013

@danielballan ?

@jreback
Copy link
Contributor

jreback commented Oct 7, 2013

hows this coming?

@danielballan
Copy link
Contributor

I will open this up once #5096 is merged....

@jreback
Copy link
Contributor

jreback commented Oct 13, 2013

@danielballan go for it!

@danielballan
Copy link
Contributor

@hayd, please take a look at #5222 and see if my tests look good to you.

jreback added a commit that referenced this issue Oct 15, 2013
BUG: Groupby filter maintains ordering, closes #4621
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