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

wesm opened this issue Oct 26, 2011 · 2 comments


Copy link

commented Oct 26, 2011

something like

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

This comment has been minimized.

Copy link

commented Nov 13, 2011

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

with a Cython distinct_count_level_1d function?


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:


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


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