I want to make a matrix whose elements are numbers in a few columns and strings in other columns. Then, I want to sort them based on numbers in one of the columns that contains numbers. I tried using numpy but it did not work. What's the easiest way to do so? Pandas, Tuple, or something else?
import numpy as np
a=np.array([[10,'b'],[2,'z'],[4,'r']])
print(a)
print(np.sort(a))
Output:
array([['10', 'b'],
['2', 'z'],
['4', 'r']], dtype='<U11')
array([['10', 'b'],
['2', 'z'],
['4', 'r']], dtype='<U11')
It seems that it has converted the numbers to strings.
a=np.array([(10,'b'),(2,'z'),(4,'r')],dtype='|i4, c')