London_data.loc[london_data["month"] == 6]["TemperatureC"]. What is the role of ".loc"?

I have a question about the Variance in Weather exercise. I am looking at Step 8.

We want to filter by the "month" column! The following line of code will create a variable that gets the temperature from the rows where "month" is 6 . These will be all of the rows from the month of June.

june = london_data.loc[london_data["month"] == 6]["TemperatureC"]

What is the role of .loc here?
I tried running the following code

june = london_data[london_data[“month”] == 6][“TemperatureC”]

And the result looks exactly the same.

Do you have a link to the lesson?

.loc[] is a function that will return a series based on a condition. You can use .loc with rows or columns, slices of data or even a specific cell.

See the docs:

Thanks. Here is the link to the exercise.

I tried doing it without “.loc” and everything seems to be OK. I am not sure what the point of including “.loc” is.

Because they want you to become familiar with it (?). Also, if I’m not mistaken it’s less processing time when you use that method. You can use it on a series or data frame.
Check out alternative resources too, beyond the pandas docs.