The first three max value in a column in python

后端 未结 1 1932
野的像风
野的像风 2021-01-21 20:30

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
         


        
相关标签:
1条回答
  • 2021-01-21 21:03

    you want either

    # get first three
    census_df['COUNTY'].head(3)
    

    or

    # get largest three
    census_df['COUNTY'].nlargest(3)
    

    if you want the records with the 3 largest COUNTY values

    census_df.iloc[census_df['COUNTY'].argsort()[-3:]]
    
    0 讨论(0)
提交回复
热议问题