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 "count distinct" function, useful for groupby #297

Closed
wesm opened this issue Oct 26, 2011 · 2 comments

Comments

@wesm
Copy link
Member

commented Oct 26, 2011

something like

def dist(x):
       return len(np.unique(x))
@changhiskhan

This comment has been minimized.

Copy link
Contributor

commented Nov 13, 2011

len(np.unique(self.dropna())) ?

with a Cython distinct_count_level_1d function?

@wesm

This comment has been minimized.

Copy link
Member Author

commented Nov 14, 2011

Maybe this should just be a groupby instance methods-- like Series now has the value_counts method so you can do:

len(s.value_counts())

but in a groupby scenario, you could do:

s.groupby(grouper).agg(lambda x: len(x.value_counts()))

but that's a bit verbose. Maybe like

s.groupby(grouper).nunique()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.