Python Pandas Error: KeyError: 0 [How to Solve]

Keyerror: error reported by 0

The following are error codes

I call my own library function and use apply to realize vlookup in Excel. The following is the code

data2 = super_function.vlook_up(data1, ['material group', 'material description'], data, ['material group', 'material group description'])

Error message

KeyError: 0

Error reporting reason

This kind of error reporting is due to the index problem. As a result, some numbers were deleted during the original data processing, resulting in the index starting from 6 instead of 0.

Solution:

Just reassign the index

data1.index = list(range(len(data1)))

result

Run successfully.

Read More: