character to integer python code example
Example 1: python convert character to integer
>>> chr(97)
'a'
>>> ord('a')
97
>>> int('1')
1
Example 2: python: convert variable as character
df['myvar'] = df['myvar'].astype(str)
Example 3: encoding character or string to integer in python
note:text contains your string or already read textfile
import numpy as np
text = 'hello'
vocab=sorted(set(text))
char_to_ind = {char:ind for ind,char in enumerate(vocab)}
encoded_text = np.array([char_to_ind[c]for c in text])
your string has been encoded