@@ -2796,13 +2796,18 @@ def sort(self, columns=None, column=None, axis=0, ascending=True,
2796
2796
columns : object
2797
2797
Column name(s) in frame. Accepts a column name or a list or tuple
2798
2798
for a nested sort.
2799
- ascending : boolean, default True
2800
- Sort ascending vs. descending
2799
+ ascending : boolean or list, default True
2800
+ Sort ascending vs. descending. Specify list for multiple sort
2801
+ orders
2801
2802
axis : {0, 1}
2802
2803
Sort index/rows versus columns
2803
2804
inplace : boolean, default False
2804
2805
Sort the DataFrame without creating a new instance
2805
2806
2807
+ Examples
2808
+ --------
2809
+ >>> result = df.sort(['A', 'B'], ascending=[1, 0])
2810
+
2806
2811
Returns
2807
2812
-------
2808
2813
sorted : DataFrame
@@ -2826,11 +2831,16 @@ def sort_index(self, axis=0, by=None, ascending=True, inplace=False):
2826
2831
by : object
2827
2832
Column name(s) in frame. Accepts a column name or a list or tuple
2828
2833
for a nested sort.
2829
- ascending : boolean, default True
2830
- Sort ascending vs. descending
2834
+ ascending : boolean or list, default True
2835
+ Sort ascending vs. descending. Specify list for multiple sort
2836
+ orders
2831
2837
inplace : boolean, default False
2832
2838
Sort the DataFrame without creating a new instance
2833
2839
2840
+ Examples
2841
+ --------
2842
+ >>> result = df.sort_index(by=['A', 'B'], ascending=[1, 0])
2843
+
2834
2844
Returns
2835
2845
-------
2836
2846
sorted : DataFrame
@@ -2846,14 +2856,17 @@ def sort_index(self, axis=0, by=None, ascending=True, inplace=False):
2846
2856
assert (axis == 0 )
2847
2857
if isinstance (by , (tuple , list )):
2848
2858
keys = [self [x ].values for x in by ]
2849
- indexer = _lexsort_indexer (keys )
2859
+ indexer = _lexsort_indexer (keys , orders = ascending )
2850
2860
else :
2851
2861
indexer = self [by ].values .argsort ()
2862
+ if not ascending :
2863
+ indexer = indexer [::- 1 ]
2864
+ elif isinstance (labels , MultiIndex ):
2865
+ indexer = _lexsort_indexer (labels .labels , orders = ascending )
2852
2866
else :
2853
2867
indexer = labels .argsort ()
2854
-
2855
- if not ascending :
2856
- indexer = indexer [::- 1 ]
2868
+ if not ascending :
2869
+ indexer = indexer [::- 1 ]
2857
2870
2858
2871
if inplace :
2859
2872
if axis == 1 :
0 commit comments