2. Sort Values Inplace - Deepstash

Understanding machine learning models

Improving data analysis and decision-making

How Google uses logic in machine learning

Discover 95 similar ideas in

It takes just

14 mins to read

2. Sort Values Inplace

In the previous sorting, one thing you may have notices is that the `sort_values `method will create a new `DataFrame `object, as shown below.

To avoid creating a new DataFrame, you can request the sorting to be done inplace by setting the `inplace `parameter. When you do that, note that calling `sort_values `will return `None `.

8

MORE IDEAS ON THIS

5. Sort by Descending Orders

As we’ve seen so far, every sorting is done using the ascending order, which is the default behavior. However, we often want to have the data sorted by a descending order. We can take advantage of the `ascending `parameter.

What should we do if we sort by multiple columns and ha...

8

1. Sort by a Single Column

In this article, we’ll be using the flights dataset, which records the monthly passenger...

8

6. Sort by Custom Functions

Apparently, the sorted data isn’t something that we expect — the months are not in the desired order. To make this happen, we can take advantage of the `sort_method `taking a `key `parameter, to which we can pass a custom function for sorting, just like Python’s built-in

8

8. Don’t Forget about NANs

It’s important to remember that your datasets can always contain NANs. Unless you’ve examined your data quality and know that there are no NANs, you should pay attention to that. When we sort values, these NANs are placed behind all the other valid values, by default. If we want to change this de...

8

7. Sort Lexicographically Unordered Columns After Casting to Categorical

The above sorting using the `key `parameter can be confusing to some people. Is there a cleaner way? Pandas is arguably the most versatile library for data processing, and you can expect that there is something neat to solve this relatively common problem — converting these lexicograph...

9

4. Sort by Multiple Columns

We don’t always need one column for sorting. In many cases, we need to sort the data frame by multiple columns. It’s also simple with sort_values because `by `doesn’t only take a single column but also a list of columns without any special syntax.

8

3. Reset Index After Sorting

In the previous sorting, you may notice that the index goes with each sorted row, which puzzles me sometimes, when I want the sorted DataFrame has an ordered index. In this case, you can either reset the index after sorting, or simply take advantage of the `ignore_index `parameter, as ...

8

CURATED FROM

CURATED BY

Related collections

More like this

Improving your inner world

Three main ways to build the foundation of your inner life is:

• Build order: Build a routine centred around activities you care about, to turn isolation into enjoyable solitude. This can be done by creating habits for your exercise, personal projects,...

Get organized

1. Carry a homework planner at all times. Entering homework, projects, tests and assignments as soon as they are assigned will make sure they aren’t forgotten about.

Pay attention in class

1. It’s important to concentrate and avoid distractions when t...

Explore the World’sBest Ideas

200,000+ ideas on pretty much any topic. Created by the smartest people around & well-organized so you can explore at will.

An Idea for Everything

Explore the biggest library of insights. And we've infused it with powerful filtering tools so you can easily find what you need.

Knowledge Library

Powerful Saving & Organizational Tools

Save ideas for later reading, for personalized stashes, or for remembering it later.

Organize your ideas & listen on the go. And with Pro, there are no limits.

Listen on the go

Just press play and we take care of the words.

Never worry about spotty connections

No Internet access? No problem. Within the mobile app, all your ideas are available, even when offline.

Get Organized with Stashes

Ideas for your next work project? Quotes that inspire you? Put them in the right place so you never lose them.

Join

2 Million Stashers

4.8

5,740 Reviews

App Store

4.7

72,690 Reviews

Sean Green

Great interesting short snippets of informative articles. Highly recommended to anyone who loves information and lacks patience.

Ashley Anthony

This app is LOADED with RELEVANT, HELPFUL, AND EDUCATIONAL material. It is creatively intellectual, yet minimal enough to not overstimulate and create a learning block. I am exceptionally impressed with this app!

Best app ever! You heard it right. This app has helped me get back on my quest to get things done while equipping myself with knowledge everyday.

samz905

Don’t look further if you love learning new things. A refreshing concept that provides quick ideas for busy thought leaders.

Ghazala Begum

Even five minutes a day will improve your thinking. I've come across new ideas and learnt to improve existing ways to become more motivated, confident and happier.

Giovanna Scalzone

Brilliant. It feels fresh and encouraging. So many interesting pieces of information that are just enough to absorb and apply. So happy I found this.

Laetitia Berton

I have only been using it for a few days now, but I have found answers to questions I had never consciously formulated, or to problems I face everyday at work or at home. I wish I had found this earlier, highly recommended!

Jamyson Haug

Great for quick bits of information and interesting ideas around whatever topics you are interested in. Visually, it looks great as well.

20x Faster

without
deepstash

with
deepstash

with

deepstash

Unlimited idea saving & library

Unlimited history

Unlimited listening to ideas