Skip to content
Advertisement

How can I sort 2d array includes only string characters in Python?

There is an array as below;

JavaScript

I used the following codes to sort this array by the second column but without success. Is there anyone to help?

JavaScript

Advertisement

Answer

np.take(x, x[:, 1].astype(int).argsort(), 0)
You may just cast the values for sorting. The overall result of you np.take() will remain as strings.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement