[Python] If we have a listlike key, _check_indexing_error will raise in dataset

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying this housing dataset trying to fetch how many houses built before 1960 have a waterfront, but when I'm writing the code it showing error can anyone explain why this is happening.

    As per the I'm trying to fetch the column g = df[(df["built"] < 1960)]

    KeyError Traceback (most recent call last) /usr/local/lib/python3.11/dist-packages/pandas/core/indexes/base.py in get_loc(self, key) 3804 try: -> 3805 return self._engine.get_loc(casted_key) 3806 except KeyError as err:

    index.pyx in pandas._libs.index.IndexEngine.get_loc()

    index.pyx in pandas._libs.index.IndexEngine.get_loc()

    pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

    pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

    KeyError: 'built'

    The above exception was the direct cause of the following exception:

    KeyError Traceback (most recent call last) 2 frames /usr/local/lib/python3.11/dist-packages/pandas/core/indexes/base.py in get_loc(self, key) 3810 ): 3811 raise InvalidIndexError(key) -> 3812 raise KeyError(key) from err 3813 except TypeError: 3814 # If we have a listlike key, _check_indexing_error will raise

    KeyError: 'built'

    enter image description here

    Continue reading...

Compartilhe esta Página