Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Pandas DataFrame nsmallest() 方法

❮ DataFrame 参考


示例

返回“Calories”列值最小的 10 行

在本例中,我们使用了一个名为 data.csv 的 .csv 文件

import pandas as pd

df = pd.read_csv('data.csv')

newdf = df.nsmallest(10, "Calories")
自己尝试 »

定义和用法

The nlargest() 方法根据指定列的最小值对 DataFrame 进行排序,然后返回从顶部开始的指定行数。


语法

dataframe.nsmallest(n, columns, keep)

参数

The keep 参数是一个 关键字参数

参数 描述
n   必填,数字,指定要返回的行数
columns   可选,字符串(列标签)或列标签列表,指定要排序的列
keep 'all'
'first'
'last'
可选,默认为 'last',指定如何处理重复行。

返回值

一个包含布尔值的 DataFrame

此方法不会更改原始 DataFrame。


❮ DataFrame 参考

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.