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.
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.