O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Locating the n-smallest and n-largest values

Sometime we need to know the n-smallest and n-largest values in a dataset. These can be found using .nsmallest() and .nlargest(). The following code demonstrates this by returning the 4-smallest values for MSFT.

And likewise, the 4-largest values.

The form for a series is slightly different since there are no columns to specify.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required