1
resposta

KeyError traceback

Ao tratar os dados e tentar excluir os valores nulos me deparei com esse erro:

KeyError Traceback (most recent call last) in <cell line: 1>() ----> 1 df.drop(registros_a_remover, axis=0,inplace=True)

5 frames /usr/local/lib/python3.10/dist-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs) 329 stacklevel=find_stack_level(), 330 ) --> 331 return func(*args, **kwargs) 332 333 # error: "Callable[[VarArg(Any), KwArg(Any)], Any]" has no

/usr/local/lib/python3.10/dist-packages/pandas/core/frame.py in drop(self, labels, axis, index, columns, level, inplace, errors) 5397 weight 1.0 0.8 5398 """ -> 5399 return super().drop( 5400 labels=labels, 5401 axis=axis,

/usr/local/lib/python3.10/dist-packages/pandas/util/_decorators.py in wrapper(*args, **kwargs) 329 stacklevel=find_stack_level(), 330 ) --> 331 return func(*args, **kwargs) 332 333 # error: "Callable[[VarArg(Any), KwArg(Any)], Any]" has no

/usr/local/lib/python3.10/dist-packages/pandas/core/generic.py in drop(self, labels, axis, index, columns, level, inplace, errors) 4503 for axis, labels in axes.items(): 4504 if labels is not None: -> 4505 obj = obj._drop_axis(labels, axis, level=level, errors=errors) 4506 4507 if inplace:

/usr/local/lib/python3.10/dist-packages/pandas/core/generic.py in _drop_axis(self, labels, axis, level, errors, only_slice) 4544 new_axis = axis.drop(labels, level=level, errors=errors) 4545 else: -> 4546 new_axis = axis.drop(labels, errors=errors) 4547 indexer = axis.get_indexer(new_axis) 4548

/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in drop(self, labels, errors) 6932 if mask.any(): 6933 if errors != "ignore": -> 6934 raise KeyError(f"{list(labels[mask])} not found in axis") 6935 indexer = indexer[~mask] 6936 return self.delete(indexer)

KeyError: "['Tipo', 'Bairro', 'Quartos', 'Vagas', 'Suites', 'Area', 'Valor', 'Condominio', 'IPTU'] not found in axis"

1 resposta

está sendo buscado o nome das colunas no index, confere se o código do registros a remover está certo:

registros_a_remover = df.query('Valor == 0 | Condominio == 0').index