Why is reset_index not set back to districts?

Screen Link:

My Code:

districts = districts.reset_index(inplace=True)

What I expected to happen:

Districts would only ‘keep’ the reset index function if I related it back to districts, like many of the other functions used so far in this course.

What actually happened:

districts is a NoneType, but we expected it to be a DataFrame.

As the error points out, districts is of type None and not a DataFrame. You need to make sure that whatever code you used to create districts before you use the above code is working as intended. Because as of now, it’s not a DataFrame and is likely “empty”.

This is my question though, throughout this course we’ve often had to equate changes back to the original variable. Why don’t we have to do this with reset_index?

My mistake. I misinterpreted your question.

The reason is related to the inplace argument. I believe this has been covered in a prior Mission, although the exact source is a bit difficult to find. You could check out the documentation, but my answer to another similar question should help you out.

That answer focuses on a different function than reset_index() but the functioning of inplace is the same.

1 Like