Sep 27, 2022

[Python] how to find the first N largest/smallest values

import pandas as pd

temp= pd.read_csv("temp.txt", delimiter="\t", skipinitialspace=True, encoding= "utf-8")
print(temp["score"].nlargest(5))    # print top 5 values
print(temp["score"].smallest(5))    # print bottom 5 values

print(temp.loc[((temp['score'] >80) & (temp['score'] <=90))  |  ((temp['math'] >=80) & (temp['math'] <90))].nlargest(5))    # print conditioned top 5 values  

No comments:

Post a Comment