Skip to content

DataFrame.nlargest result error #16314

Closed
Closed
@flystarhe

Description

@flystarhe

Code Sample, a copy-pastable example if possible

import pandas as pd
import numpy as np

df = pd.DataFrame({'a': [1, 10, 8, 11, 8],
    'b': list('abdce'),
    'c': [1.0, 2.0, np.nan, 3.0, 4.0]})
print('_________')
print(df.nlargest(10,['a','b']))

Problem description

DataFrame的nlargest在遇到rank相同的情况时,结果错误。如下,第二行和第四行反复出现了。

Expected Output

    a  b    c
3  11  c  3.0
1  10  b  2.0
2   8  d  NaN
4   8  e  4.0
2   8  d  NaN
4   8  e  4.0
0   1  a  1.0
[Finished in 0.6s]

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs InfoClarification about behavior needed to assess issueReshapingConcat, Merge/Join, Stack/Unstack, ExplodeUsage Question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions