Why does the code work inspite of not saving the change in the class_size dataframe?

Screen Link:

My Code:

 import numpy
class_size = class_size.groupby("DBN").agg(numpy.mean)
list(class_size.index) #Checking to see the index
**class_size.reset_index(inplace=True)** #why is this not being assigned to class_size?
data["class_size"] = class_size

What I expected to happen:
I was not expecting this change to happen in the below code
class_size.reset_index(inplace=True), because for the change to take effect are we not supposed to write the code like this ? see below


What actually happened:

It works even without assigning the change to the dataframe

Hi @swarupmalli,

Since you used inplace=True, the variable class_size was changed inplace, i.e. it was re-assigned to itself. Alternatively, instead of that line, you can use:

class_size = class_size.reset_index()

this time without inplace=True. The result will be the same.

Thank you Elena! Makes sense now :grinning:

1 Like