Dc_listings is not defined

Screen Link:
Multivariate K-Nearest Neighbors | Dataquest

My Code:

from scipy.spatial import distance
normalized_listings = (dc_listings - dc_listings.mean())/(dc_listings.std())
normalized_listings['price'] = dc_listings['price']

first_listing = normalized_listings.iloc[0][['accommodates', 'bathrooms']]
fifth_listing = normalized_listings.iloc[4][['accommodates', 'bathrooms']]
first_fifth_distance = distance.euclidean(first_listing, fifth_listing)
print(first_fifth_distance)

What I expected to happen:
The code was meant to output the Euclidean distance between the two attributes in the code above.

What actually happened:
But instead I have

NameError: name 'dc_listings' is not defined

I tried using the code in the answer section, it brought out the same thing.

How it works on their backend can be a bit difficult to understand/figure out at times.

But, I ran their solution code and got the same error as you did. Then I went to the previous Mission Step, ran the solution code in it, then came back to this Step, reran their solution and there was no more error.

So, try to follow these two steps -

  1. Go back to the previous Mission Step and run your code again for that step.

  2. Come back to this Step (where you are facing the issue) and don’t calculate normalized_listings again. Just use it assuming you already have calculated it (like their solution does)

Just try these two steps and let me know.

Thanks so much. The two highlighted steps worked.

1 Like