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

Making categoricals comparable #3943

Closed
hayd opened this issue Jun 18, 2013 · 5 comments · Fixed by #7217
Closed

Making categoricals comparable #3943

hayd opened this issue Jun 18, 2013 · 5 comments · Fixed by #7217
Labels
Milestone

Comments

@hayd
Copy link
Contributor

hayd commented Jun 18, 2013

another example:

http://stackoverflow.com/questions/23814368/sorting-pandas-categorical-labels-after-groupby

At the moment bins / buckets are simply strings, so you can't sort them properly.

A=pd.qcut(X['x'], [0,0.25,0.5,0.75,1.0])

In [28]: A[0]
Out[28]: '(0.635, 2.4]'

In [29]: type(A[0])
Out[29]: str

The dtype of the Index is object (because these are strings), maybe we could just have these as a subclass of strings where:

def __lt__(self, other):
    from ast import literal_eval
    return literal_eval(self) < literal_eval(other)

Can put together pr if seems reasonable.

@hayd
Copy link
Contributor Author

hayd commented Jun 18, 2013

@cpcloud
Copy link
Member

cpcloud commented Jun 18, 2013

hm why the ast? literal_eval('(1,2]') won't evaluate because that's not valid syntax. found this on ordering intervals which is a special case of partial ordering

@hayd
Copy link
Contributor Author

hayd commented Jun 18, 2013

oh sorry I meant literal_eval(self[1:-1])

@cpcloud
Copy link
Member

cpcloud commented Jun 18, 2013

that ordering is a partially ordered R2. does that make the most sense for intervals? it's probably the most intuitive...

@hayd
Copy link
Contributor Author

hayd commented Jun 18, 2013

Well, to be honest it could even just be the first element, since in this case bins are disjoint (is this the case for all categoricals?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants