This anwser said that I can use df.groupby('id')['value'].nlargest(30)
to get top30 rows for each group. But how to get the rows form top2 to top31 for each group? Is there a function that can do the similar thing like pandas.Series.nlargest
尝试apply
.iloc
和.iloc
来获取,例如您想要1:30
df.sort_values('value').groupby('id').value.apply(lambda x : x.iloc[1:30])
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.