python中一列的前三个最大值 [英] The first three max value in a column in python
本文介绍了python中一列的前三个最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Python 新手.我想知道如何在 Python 中提取列的前三个值.我使用了 CSV 文件.这是我的代码:
I am new in Python. I would like to know how should I extract the first three value of a column in Python. I used CSV file. Here is my code:
import pandas as pd
census_df = pd.read_csv('census.csv')
def answer_five():
return census_df['COUNTY'].idxmax(3)
answer_five()
推荐答案
你想要
# get first three
census_df['COUNTY'].head(3)
或
# get largest three
census_df['COUNTY'].nlargest(3)
如果您想要具有 3 个最大 COUNTY
值的记录
if you want the records with the 3 largest COUNTY
values
census_df.iloc[census_df['COUNTY'].argsort()[-3:]]
这篇关于python中一列的前三个最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文