XPub to YPub Converter (python) - Last digits wrong
The base58.b58decode and base58.b58encode functions only do the Base 58 decode/encode. However xpubs are encoded with Base 58 Check encoding. The difference is that Base 58 Check encoding computes a checksum of the payload and appends the first 4 bytes of that to the payload before the base 58 encoding.
You need to be using base58.b58decode_check and base58.b58encode_check which will drop the checksum for the decode, and add the checksum for the encode.