Skip to content

grouped.filter with dropna option #10780

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
leo4183 opened this issue Aug 10, 2015 · 3 comments · Fixed by #14926
Closed

grouped.filter with dropna option #10780

leo4183 opened this issue Aug 10, 2015 · 3 comments · Fixed by #14926
Milestone

Comments

@leo4183
Copy link

leo4183 commented Aug 10, 2015

in Pandas 0.16.2:

grouped = a.groupby(idx)
grouped.filter(lambda x: x.mean()>0.0, dropna=False)

in case there was no group whose x.mean() was larger than zero, an AttributeError: 'list' object has no attribute 'astype' would be raised (rather than returning an all NaN dataframe/serie in previous versions).

@jreback
Copy link
Contributor

jreback commented Aug 10, 2015

pls show a complete example that can be copy pasted

@leo4183
Copy link
Author

leo4183 commented Aug 10, 2015

a concrete example:

import numpy as np
import pandas as pd

row = 9
a   = pd.Series(np.random.rand(row),index=np.repeat([1,2,3],3))
gp  = a.groupby(level=0)
empty_serie  = gp.filter(lambda x: x.mean()>1)
error_raised = gp.filter(lambda x: x.mean()>1, dropna=False)

where the empty_serie would be an empty serie as expected. however an attribute error would be raised for the last line

@jreback
Copy link
Contributor

jreback commented Aug 11, 2015

hmm, that's not very friendly!. pull-requests to fix welcome!

@jreback jreback added this to the Next Major Release milestone Aug 11, 2015
@jreback jreback modified the milestones: 0.20.0, Next Major Release Dec 20, 2016
mroeschke added a commit to mroeschke/pandas that referenced this issue Dec 20, 2016
jreback pushed a commit that referenced this issue Dec 20, 2016
ShaharBental pushed a commit to ShaharBental/pandas that referenced this issue Dec 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants