File tree Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Original file line number Diff line number Diff line change @@ -400,17 +400,10 @@ Top N rows per group
400
400
ROW_NUMBER() OVER(PARTITION BY day ORDER BY total_bill DESC) AS rn
401
401
FROM tips t
402
402
)
403
- WHERE rn <= 3
403
+ WHERE rn < 3
404
404
ORDER BY day, rn;
405
405
406
- .. ipython :: python
407
-
408
- (tips.sort_values([' total_bill' ], ascending = False )
409
- .groupby(' sex' )
410
- .head(3 )
411
- )
412
-
413
- Let's add an `RN ` (Row Number) column
406
+ Let's add a helper column: `RN ` (Row Number)
414
407
415
408
.. ipython :: python
416
409
@@ -425,7 +418,7 @@ the same using `rank(method='first')` function
425
418
.. ipython :: python
426
419
427
420
tips[' rnk' ] = (tips.groupby([' day' ])[' total_bill' ]
428
- .rank(method = ' first' , ascending = False
421
+ .rank(method = ' first' , ascending = False )
429
422
)
430
423
tips.loc[tips[' rnk' ] < 3 ].sort_values([' day' ,' rnk' ])
431
424
You can’t perform that action at this time.
0 commit comments