Before jumping to Cython, remove things like exponentiation and all the calls to `ord`:<p><pre><code> def column_to_index(col):
col_index = 0
for byte in bytearray(col):
col_index *= 26
col_index += byte - 64
return col_index - 1
</code></pre>
FWIW, you _can_ vectorize this, albeit it's neither simple nor fast, due to Numpy's fixed overheads. If you convert thousands of strings at once, though, it's probably reasonably speedy.<p><pre><code> import numpy
from numpy import arange
place_values = 26 ** arange(20, dtype=object)[::-1]
overhead = numpy.add.accumulate(64 * place_values[::-1]) + 1
def column_to_index(col):
digits = bytearray(col)
length = len(digits)
summation = place_values[-length:].dot(digits)
return summation - overhead[length-1]</code></pre>