DataFrame.nlargest result error
See original GitHub issueCode 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
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
Python pandas nlargest() not working properly with keep = 'all'
Hi Chrispresso, I am trying to find the top3 result, but I want it to not drop duplicates. So, for example, if there...
Read more >pandas.DataFrame.nlargest — pandas 1.5.2 documentation
Return the first n rows with the largest values in columns , in descending order. The columns that are not specified are returned...
Read more >Pandas DataFrame nlargest() Method - Finxter
DataFrame nlargest (). The nlargest() method retrieves and returns the first n (number) of rows containing the largest column values in descending order....
Read more >Python | Pandas DataFrame.nlargest() - GeeksforGeeks
Pandas nlargest () method is used to get n largest values from a data frame or a series. Syntax: DataFrame.nlargest(n, columns, keep='first').
Read more >Become a pandas ninja with nlargest(), nsmallest(), query and ...
The result DataFrame in this case is ordered in ascending order based on columns we specify. In this section, we talk about nlargest...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@flystarhe your question is not clear
These might be what you want
better still since it does deals string format. so the df[‘’].value_counts().nlargest