xxxxxxxxxx
function sort_Function() {//Sort an array on multiple columns
var array = [
[0, 'Aluminium', 'z', 'Francis'],
[1, 'Argon', 'x', 'Ada'],
[2, 'Brom', 'x', 'John'],
[3, 'Cadmium', 3, 'Marie'],
[4, 'Fluor', 'x', 'Marie'],
[5, 'Gold', 'x', 'Ada'],
[6, 'Kupfer', 1, 'Ines'],
[7, 'Krypton', 'x', 'Joe'],
[8, 'Sauerstoff', 'x', 'Marie'],
[9, 'Zink', 2, 'Max']
];
array.sort(function (a, b) {
return a[2].toString() .localeCompare(b[2].toString()) || a[1].localeCompare(b[1]);//has to be string to compare
});
console.log(array);
}//end function
xxxxxxxxxx
# Below are quick example
# Sort multiple columns
df2 = df.sort_values(['Fee', 'Duration'],
ascending = [False, True])
# Sort by two columns
df2 = df.sort_values(['Courses', 'Discount'],
ascending = [True, True])
# Using the sorting function
df.sort_values(["Fee", "Courses"],
axis = 0, ascending = True,
inplace = True,
na_position = "first")
xxxxxxxxxx
In [11]: df1 = pd.DataFrame(np.random.randint(1, 5, (10,2)), columns=['a','b'])
In [12]: df1.sort(['a', 'b'], ascending=[True, False])
Out[12]:
a b
2 1 4
7 1 3
1 1 2
3 1 2
4 3 2
6 4 4
0 4 3
9 4 3
5 4 1
8 4 1