简体   繁体   中英

sort Pandas Dataframe based on column value

enter image description here

In my data set in height column value increases then after starts to decrease. I want to sort data only up to increase height. I don't want data after height decrease.

You can achieve this by finding the index of the max value of the height column, and then using iloc to reassign the dataframe only including the rows up to this index:

x = df.idmax()['height']
df = df.iloc[:x+1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM