TransWikia.com

Python codeblock to remove numeric characters from a column not working

Geographic Information Systems Asked on July 1, 2021

I am trying to make use of a codeblock found in this thread:

Removing numeric characters from alphanumeric value in field calculation?

I put this code into the pre-logic script field of the field calculator:

import re 
def strip_digits(s):
    return re.sub("d+", "", s)

And call it in the expression as below with the column in question substituted for column_name:

strip_digits(!column_name!)

And get the following when running it on a column of data type long:

ERROR 000539: Error running expression: strip_digits(171752)<type 'exceptions.TypeError'>:expected string or buffer

I can’t seem to figure out what is going wrong, any ideas?

One Answer

Your input and output column should be text type. It's expecting a string or buffer and you passed probably integer or double.

Correct answer by dmh126 on July 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP