Skip to content

Ability to Sort DataFrame by Transformed Values #6663

@cancan101

Description

@cancan101

Let's say I have a DataFrame of stock returns. It would be great to be able to sort easily the DataFrame by the abs value of the returns. Currently I do this by inserting a new column and then sorting on the new column and than slicing on the original columns. This is ungainly:

ret["returns_abs"] = ret.returns.abs()
ret.sort("returns_abs", ascending=False)[["returns", "key"]]

It would be great if I could either pass a Series or a function to the sort method:

ret.sort(ret.returns.abs(), ascending=False)

or

ret.sort(lambda x: abs(x.ix["returns"], ascending=False)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions