On 2021-02-21 at 09:28:39 -0500,
C W <tmrs...@gmail.com> wrote:

> I got it to work! I defined a separate function, and put it into
> df['col_1'].apply().
> 
> Not the most elegant, but it worked. I'm also curious how people on this
> mailing list would do it.

I don't know anything about pandas, but for one string of digits
(there's no clear requirements for how to handle leading zeros in the
input or the output), I'd end up with something like this:

OFF_BY_3_MAPPING = dict(zip('0123456789', '7890123456'))
def off_by_3(digits):
    return ''.join(OFF_BY_3_MAPPING[c] for c in digits)
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to