Since the function is a one-liner, you can just copy the return
expression into the body of the lambda.
tips.groupby('smoker').apply(lambda df, n=3, column='tip_pct': df.sort_values(by=column, ascending=False)[:n])
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.