sort_index() Method - Teradata Python Package

Teradata® Python Package User Guide

Product
Teradata Python Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-29
dita:mapPath
rkb1531260709148.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
B700-4006
lifecycle
previous
Product Category
Teradata Vantage

Use the sort_index() method to get object sorted by labels (along an axis) in either ascending or descending order for a teradataml DataFrame.

Example: Default behavior of sort_index() when no arguments is given.

>>> load_example_data("dataframe","scale_housing_test")
>>> df = DataFrame.from_table('scale_housing_test')
>>> df
          id    price  lotsize  bedrooms  bathrms  stories
types                                                    
classic   14  36000.0   2880.0       3.0      1.0      1.0
bungalow  11  90000.0   7200.0       3.0      2.0      1.0
classic   15  37000.0   3600.0       2.0      1.0      1.0
classic   13  27000.0   1700.0       3.0      1.0      2.0
classic   12  30500.0   3000.0       2.0      1.0      1.0
>>> df.sort_index()
          id    price  lotsize  bedrooms  bathrms  stories
types                                                    
bungalow  11  90000.0   7200.0       3.0      2.0      1.0
classic   13  27000.0   1700.0       3.0      1.0      2.0
classic   12  30500.0   3000.0       2.0      1.0      1.0
classic   14  36000.0   2880.0       3.0      1.0      1.0
classic   15  37000.0   3600.0       2.0      1.0      1.0

Example: Use sort_index() with DESCENDING for respective axis.

>>> load_example_data("dataframe","scale_housing_test")
>>> df = DataFrame.from_table('scale_housing_test')
>>> df.sort_index(1, False)
          stories    price  lotsize  id  bedrooms  bathrms
types                                                    
classic       1.0  36000.0   2880.0  14       3.0      1.0
bungalow      1.0  90000.0   7200.0  11       3.0      2.0
classic       1.0  37000.0   3600.0  15       2.0      1.0
classic       2.0  27000.0   1700.0  13       3.0      1.0
classic       1.0  30500.0   3000.0  12       2.0      1.0

Example: Use sort_index() with type of sorting algorithm.

>>> load_example_data("dataframe","scale_housing_test")
>>> df = DataFrame.from_table('scale_housing_test')
>>> df.sort_index(1, True, 'mergesort')
          bathrms  bedrooms  id  lotsize    price  stories
types                                                    
classic       1.0       3.0  14   2880.0  36000.0      1.0
bungalow      2.0       3.0  11   7200.0  90000.0      1.0
classic       1.0       2.0  15   3600.0  37000.0      1.0
classic       1.0       3.0  13   1700.0  27000.0      2.0
classic       1.0       2.0  12   3000.0  30500.0      1.0