Skip to content

BUG: groupby(axis=0).rank(axis=1) #41320

Closed
@jbrockmendel

Description

@jbrockmendel

Looks like it is discarding the axis=1

df = DataFrame({0: [1, 3, 5, 7], 1: [2, 4, 6, 8], 2: [1.5, 3.5, 5.5, 7.5]}, index=["a", "a", "b", "b"])
gb = df.groupby(level=0, axis=0)

res = gb.rank(axis=1)

# This should match what we get when "manually" operating group-by-group
expected = concat([df.loc["a"].rank(axis=1), df.loc["b"].rank(axis=1)], axis=0)

>>> res
     0    1    2
a  1.0  1.0  1.0
a  2.0  2.0  2.0
b  1.0  1.0  1.0
b  2.0  2.0  2.0


>>> expected
     0    1    2
a  1.0  3.0  2.0
a  1.0  3.0  2.0
b  1.0  3.0  2.0
b  1.0  3.0  2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffBug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions