This is a stack trace. It shows not just where the actual error occurred directly, but also what the program was doing while it occurred.
- The code
df.loc['origin' == 'US'](on line 6) is at the top of the trace, meaning it’s the root cause, but this by itself is not an error. This will evaluate'origin' == 'US'toFalse, since this is a simple string comparison and the strings aren’t equal, and then it will evaluatedf.loc[False]. - Evaluating this requires looking up the key
Falsein the objectdf.loc. This calls the__getitem__method, which is called whenever you access a key using the syntaxa[b]. - The
__getitem__method has a linereturn self._getitem_axis(maybe_callable, axis=axis)calling a method named_getitem_axis. This is on line 1500 of the file. - The
_getitem_axismethod has a linereturn self._get_label(key, axis=axis), calling a method_get_label. This is line 1913 of the file. - …and so on…
- Finally, the method
pandas._libs.index.Int64Engine._check_typechecks the type of the key. The key isFalse, which is of typebool. Presumably, this is not a valid type for the lookup you were doing, so the_check_typemethod raises aKeyError.
solved What are the thousands of lines in error in python