Pandas nlargest method | Get top n rows of a data frame | Python Pandas Tutorial

preview_player
Показать описание
In this video, we discuss how to get the top n rows of a pandas data frame based on some columns using the nlargest method.

Рекомендации по теме
Комментарии
Автор

Very helpful! I spent more time googling how to do this and struggling to implement it than it took to just watch this video and now I have exactly what I need!

toya
Автор

Thanks Aditya!!

I am working on an analysis - where in when I am trying to mention column-name in nlargest (query mentioned below) - then compiler throws error "Series.nlargest() takes from 1 to 3 positional arguments but 4 were given".

> medical_appointments.groupby(by='gender').agg(total=('appointmentid', 'count')).reset_index().apply(lambda x: x.nlargest(1, 'total', 'all'))

When I remove 'total' from nlargest argument list - the method works as expected. I am confused when nlargest argument lists expects column-name and when not. Please reply if you have an idea..

PrateekTrivedi
Автор

how do you do this for categorical columns

zoomphotografie
Автор

Nice one Chacha!! I didn't know about these functions

anon
Автор

Nice video please continue the series brother

Mukeshkumar-ylqq
Автор

Sir i tried this but it's saying it has dtype and nlargest method cannot be used

sakshideo