Assignment Differences

Screen Link:
M136 Page 9

My Code (the pertinent line):

data['survey'] = survey.loc[:, cols_to_keep]

Answer code:

survey = survey.loc[:, cols_to_keep]
data['survey'] = survey

As far as I can tell, my code should lead to the same result as the answer code, but is flagged as incorrect. Can someone help me understand why please? It seems to me that there is a nuance between these two approaches that is not obvious to me.

No. It’s about the specific instructions and the exercise. We ask to assign something to survey. You didn’t do this.

data['survey'] = survey.loc[:, cols_to_keep]

Your approach above is correct. And it is no different than the one in the solution they provide.

The distinction is related to what specifically is expected by their grader based on their instructions

They expect that survey should be replaced by the data from those columns as well. Hence, the step below

survey = survey.loc[:, cols_to_keep]

is required. If you click on Submit you will notice that the Variable survey is the one which gets highlighted (red or green, depending on if it’s right). So, that’s what they are checking against.

Your code is correct in terms of making sure data["survey"] has the correct structure and data, but you need that additional step above as per their instructions as well.

1 Like

Thanks. I got a little ahead of myself then, good to know both ways work.