Please help to understand 'loc' function

My code:

boo_1 = f500["country"] == "USA"

industry_usa = f500[boo_1, "industry"]

'Series' objects are mutable, thus they cannot be hashed

Question: I searched around I figured out the objects “Series” here can be changed, hence “mutatable”, so they cannot be hashed (meaning compared or changed). I have no idea how this error happened, can someone explain to me please?

Note: I added ‘loc’ and it works. I hypothesized that because with ‘loc’ function, it refers to the string as an index, hence it works. Is my hypothesis correct?

1 Like

Hey there!

Since you’re trying to index on both dimensions, you’ll need to use .loc[] here — you can omit it if you’re using shorthand to select multiple columns, but since you’re looking to select specific rows via boolean filtering, you’ll need to use the correct syntax.

As far as understanding the error, this is one of the better put ways that I’ve seen floating around:


Thank you Dustin. I read the quora’s answer, super helpful!