Data Cleaning Walkthrough: Combining the Data : 5. Computing Average Class Sizes

Screen Link:

My Code:

#Solution Code
import numpy as np
#class_size = data['class_size']
class_size = class_size.groupby('DBN').agg(np.mean)
class_size.reset_index(inplace = True)
data['class_size'] = class_size
data['class_size'].shape

#What I wrote
import numpy as np
#class_size = data['class_size']
class_size.groupby('DBN').agg(np.mean).reset_index(inplace = True)
data['class_size'] = class_size
data['class_size'].shape

Why are the two code sections above giving different results. Why is it that chaining reset_index(inplace=True) give the wrong results?

Because the inplace=True only works for reset_index. Since you are using groupby() and agg() on class_size but not saving the output of those two back into class_size that entire code line has no changes saved in the end.

Ok. Thanks. That makes sense now