Skip to content
Advertisement

Pandas groupby filter only last two rows

I am working on pandas manipulation and want to select only the last two rows for each column “B”.

How to do without reset_index and filter (do inside groupby)

JavaScript

My attempt

JavaScript

Required output

JavaScript

Advertisement

Answer

Try:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement