Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Introduction to pandas Exploring pandas Exploration Methods

sort_values creates new DataFrame

Craig says this:

You'll notice that sort_values call actually created a new DataFrame. If you want to permanently change the sort from the default (sorted by index), you can pass True as an argument to the inplace keyword parameter.

My question is this:

How can you tell?

1 Answer

Hi givens,

I found this a curious statement too, as I read it, and so I ran this second line:

users.sort_values(by='balance', ascending=False).head()

users.head()   # my line

And sure enough, by default, users was still sorted alphabetically by index, the first row with an index of aaron

Neat, huh?