Skip to content

Commit aca7a08

Browse files
committed
updating docs for the new sorting mechanisms - GH #10886
1 parent 70607ba commit aca7a08

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

doc/source/10min.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Sorting by values
157157

158158
.. ipython:: python
159159
160-
df.sort(columns='B')
160+
df.sort_values(by='B')
161161
162162
Selection
163163
---------
@@ -680,7 +680,7 @@ Sorting is per order in the categories, not lexical order.
680680

681681
.. ipython:: python
682682
683-
df.sort("grade")
683+
df.sort_values(by="grade")
684684
685685
Grouping by a categorical column shows also empty categories.
686686

doc/source/advanced.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ As usual, **both sides** of the slicers are included as this is label indexing.
286286
names=['lvl0', 'lvl1'])
287287
dfmi = pd.DataFrame(np.arange(len(miindex)*len(micolumns)).reshape((len(miindex),len(micolumns))),
288288
index=miindex,
289-
columns=micolumns).sortlevel().sortlevel(axis=1)
289+
columns=micolumns).sort_index().sort_index(axis=1)
290290
dfmi
291291
292292
Basic multi-index slicing using slices, lists, and labels.
@@ -458,7 +458,7 @@ correctly. You can think about breaking the axis into unique groups, where at
458458
the hierarchical level of interest, each distinct group shares a label, but no
459459
two have the same label. However, the ``MultiIndex`` does not enforce this:
460460
**you are responsible for ensuring that things are properly sorted**. There is
461-
an important new method ``sortlevel`` to sort an axis within a ``MultiIndex``
461+
an important new method ``sort_index`` to sort an axis within a ``MultiIndex``
462462
so that its labels are grouped and sorted by the original ordering of the
463463
associated factor at that level. Note that this does not necessarily mean the
464464
labels will be sorted lexicographically!
@@ -468,34 +468,34 @@ labels will be sorted lexicographically!
468468
import random; random.shuffle(tuples)
469469
s = pd.Series(np.random.randn(8), index=pd.MultiIndex.from_tuples(tuples))
470470
s
471-
s.sortlevel(0)
472-
s.sortlevel(1)
471+
s.sort_index(level=0)
472+
s.sort_index(level=1)
473473
474474
.. _advanced.sortlevel_byname:
475475

476-
Note, you may also pass a level name to ``sortlevel`` if the MultiIndex levels
476+
Note, you may also pass a level name to ``sort_index`` if the MultiIndex levels
477477
are named.
478478

479479
.. ipython:: python
480480
481481
s.index.set_names(['L1', 'L2'], inplace=True)
482-
s.sortlevel(level='L1')
483-
s.sortlevel(level='L2')
482+
s.sort_index(level='L1')
483+
s.sort_index(level='L2')
484484
485485
Some indexing will work even if the data are not sorted, but will be rather
486486
inefficient and will also return a copy of the data rather than a view:
487487

488488
.. ipython:: python
489489
490490
s['qux']
491-
s.sortlevel(1)['qux']
491+
s.sort_index(level=1)['qux']
492492
493493
On higher dimensional objects, you can sort any of the other axes by level if
494494
they have a MultiIndex:
495495

496496
.. ipython:: python
497497
498-
df.T.sortlevel(1, axis=1)
498+
df.T.sort_index(level=1, axis=1)
499499
500500
The ``MultiIndex`` object has code to **explicity check the sort depth**. Thus,
501501
if you try to index at a depth at which the index is not sorted, it will raise

doc/source/api.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ Reshaping, sorting
437437
Series.reorder_levels
438438
Series.sort_values
439439
Series.sort_index
440-
Series.sortlevel
441440
Series.swaplevel
442441
Series.unstack
443442
Series.searchsorted

doc/source/basics.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ equality to be True:
328328
df1 = pd.DataFrame({'col':['foo', 0, np.nan]})
329329
df2 = pd.DataFrame({'col':[np.nan, 0, 'foo']}, index=[2,1,0])
330330
df1.equals(df2)
331-
df1.equals(df2.sort())
331+
df1.equals(df2.sort_index())
332332
333333
Comparing array-like objects
334334
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1489,16 +1489,16 @@ The ``by`` argument can take a list of column names, e.g.:
14891489

14901490
.. ipython:: python
14911491
1492-
df1[['one', 'two', 'three']].sort_index(by=['one','two'])
1492+
df1[['one', 'two', 'three']].sort_values(by=['one','two'])
14931493
14941494
These methods have special treatment of NA values via the ``na_position``
14951495
argument:
14961496

14971497
.. ipython:: python
14981498
14991499
s[2] = np.nan
1500-
s.order()
1501-
s.order(na_position='first')
1500+
s.sort_values()
1501+
s.sort_values(na_position='first')
15021502
15031503
15041504
.. _basics.searchsorted:
@@ -1564,7 +1564,7 @@ all levels to ``by``.
15641564
.. ipython:: python
15651565
15661566
df1.columns = pd.MultiIndex.from_tuples([('a','one'),('a','two'),('b','three')])
1567-
df1.sort_index(by=('a','two'))
1567+
df1.sort_values(by=('a','two'))
15681568
15691569
15701570
Copying

doc/source/cookbook.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ Method 2 : sort then take first of each
309309

310310
.. ipython:: python
311311
312-
df.sort("BBB").groupby("AAA", as_index=False).first()
312+
df.sort_values(by="BBB").groupby("AAA", as_index=False).first()
313313
314314
Notice the same results, with the exception of the index.
315315

@@ -410,7 +410,7 @@ Sorting
410410

411411
.. ipython:: python
412412
413-
df.sort(('Labs', 'II'), ascending=False)
413+
df.sort_values(by=('Labs', 'II'), ascending=False)
414414
415415
`Partial Selection, the need for sortedness;
416416
<https://github.com/pydata/pandas/issues/2995>`__
@@ -547,7 +547,7 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
547547
548548
code_groups = df.groupby('code')
549549
550-
agg_n_sort_order = code_groups[['data']].transform(sum).sort('data')
550+
agg_n_sort_order = code_groups[['data']].transform(sum).sort_values(by='data')
551551
552552
sorted_df = df.ix[agg_n_sort_order.index]
553553

doc/source/reshaping.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ will result in a **sorted** copy of the original DataFrame or Series:
164164
index = pd.MultiIndex.from_product([[2,1], ['a', 'b']])
165165
df = pd.DataFrame(np.random.randn(4), index=index, columns=['A'])
166166
df
167-
all(df.unstack().stack() == df.sort())
167+
all(df.unstack().stack() == df.sort_index())
168168
169-
while the above code will raise a ``TypeError`` if the call to ``sort`` is
169+
while the above code will raise a ``TypeError`` if the call to ``sort_index`` is
170170
removed.
171171

172172
.. _reshaping.stack_multiple:
@@ -206,7 +206,7 @@ Missing Data
206206
These functions are intelligent about handling missing data and do not expect
207207
each subgroup within the hierarchical index to have the same set of labels.
208208
They also can handle the index being unsorted (but you can make it sorted by
209-
calling ``sortlevel``, of course). Here is a more complex example:
209+
calling ``sort_index``, of course). Here is a more complex example:
210210

211211
.. ipython:: python
212212

0 commit comments

Comments
 (0)