I was writing a function which can change a dataframe value based on user input. The dataframe was from a csv file, containing students and their information (gender, race, major, etc.), and the code intended to have the user identify any errors (ex. wrong gender) and provide the correct value, and then have the code replace it. I successfully made the code create a new dataframe with the row with all the correct values. I tried to delete (using .drop()) the old row, so I could replace it with the new row, but that’s where I got the error. At the beginning part of the code I got the value ‘student_num’ which is basically the row index.
df = df.drop(df[student_num])
but I got an error on this line which was having a problem with that index. This was the error:
3621 return self._engine.get_loc(casted_key) 3622 except KeyError as err: 3623 raise KeyError(key) from err 3624 except TypeError: 3625 # If we have a listlike key, _check_indexing_error will raise 3626 # InvalidIndexError. Otherwise we fall through and re-raise 3627 # the TypeError. 3628 self._check_indexing_error(key) KeyError: 15
Leave an answer