Skip to content

Making categoricals comparable #3943

Closed
@hayd

Description

@hayd

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions