Why does the correct answer require strings be wrapped with " rather than ' in mission 137-9?

Hi, I am confused about the behavior of code in mission 137-9.

When I use the following code, I get an empty dataframe:

data['graduation'] = data['graduation'][data['graduation']['Cohort'] == '2006']
data['graduation'] = data['graduation'][data['graduation']['Demographic'] == 'Total  Cohort']
print(data['graduation'].head()) 

however, when I replace my single quotes with double-quotes, I get the correct answer:

data["graduation"] = data["graduation"][data["graduation"]["Cohort"] == "2006"]
data["graduation"] = data["graduation"][data["graduation"]["Demographic"] == "Total Cohort"]
print(data["graduation"].head()) 

Can someone please explain this behavior? From what I’ve been able to find, these should be interchangeable?

It looks like in the first version that there are two spaces between Total and Cohort. Can you check to see if that’s the issue?

1 Like

That was the issue! Thanks, somehow I totally missed that!

1 Like