There is a huge matrix whose elements are numbers in the range of 1 to 15. I want to transform the matrix to the one whose elements be letters such that 1 becomes "a", 2 becomes "b", and so on. Finally I want to merge each row and create a sequence of it. As a simple example:
import pandas as pd
import numpy as np, numpy.random
numpy.random.seed(1)
A = pd.DataFrame (np.random.randint(1,16,10).reshape(2,5))
A.iloc[1,4]= np.NAN
A
# 0 1 2 3 4
#0 6 12 13 9 10.0
#1 12 6 1 1 NaN
If there were no Na in the dataset, I would use this code:
pd.DataFrame(list(map(''.join, A.applymap(lambda n: chr(n + 96)).as_matrix())))
Here, it gives this error:
TypeError: ('integer argument expected, got float', 'occurred at index 4')
The expected output is:
0
0 flmij
1 lfaa
The first row should have 5 elements and the second one should have 4 elements.