Guided Project:employee exit survey 3~4/11

I got stuck on 3~4/11 on this project. Even though I found the bugs by comparing the solution’s, I still have a question on when to return to the dataframe.

If I use those two lines of code:
tafe_survey_updated = tafe_survey_updated.rename(mapper, axis = 1)
Or
tafe_survey_updated.rename(mapper, axis = 1, inplace = True)
tafe_survey_updated['separationtype'].value_counts()

Both of my two lines of code went thru. But if I didn’t assign the dataframe back to tafe_survey_update, The first line of code tafe_survey_updated.rename(mapper, axis = 1)

went thru. But when I ran the second line of code:

tafe_survey_updated['separationtype'].value_counts()

It gave me the KeyError: ‘separationtype’. Why is that? Do I always have to assign the dataframe back with a variable or otherwise in the next few steps, I may encounter some errors due to the fact the system cannot even find the right dataframe?

Hello @yoyotooie! This is because when you just do tafe_survey_updated.rename(mapper, axis = 1) the renaming takes place but is not saved in the original dataframe. By default inplace = False so when you run the line above without reassigning to the dataframe inplace is False and the change doesn’t affect the dataframe.
In that case you have to reassign it to the variable with the assignment operation: tafe_survey_updated = tafe_survey_updated.rename(mapper, axis = 1)

However, if you decided to explicitly set inplace=True the change will directly affect the dataframe and no reassignment is necessary. This is a very common mistake that we make as beginners. It still happens to me from time to time.

So make sure you use inplace=True if you don’t want to explicitly do any reassignment.

2 Likes

@Yemi Thank you so much for your explicit explanation. With fewer and fewer baby-step directions in the projects, I feel it is getting more challenging.

1 Like

@yoyotooie I feel that is also the goal for us to become more independent as we progress. :smiley: One thing I do that you might find helpful is go back once in a while to former missions and re-do them. That gives me some perspective and allows me to understand even better what I had learned there because I already got to use it in the newest missions. So going back now knowing the usefulness of what I had learned helps a lot.

1 Like