Teradata Package for Python Function Reference | 20.00 - sort_index - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.
Teradata® Package for Python Function Reference - 20.00
- Deployment
- VantageCloud
- VantageCore
- Edition
- Enterprise
- IntelliFlex
- VMware
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.03
- Published
- December 2024
- ft:locale
- en-US
- ft:lastEdition
- 2024-12-19
- dita:id
- TeradataPython_FxRef_Enterprise_2000
- lifecycle
- latest
- Product Category
- Teradata Vantage
- teradataml.dataframe.dataframe.DataFrame.sort_index = sort_index(self, axis=0, ascending=True, kind='quicksort')
- DESCRIPTION:
Gets sorted object by labels (along an axis) in either ascending or
descending order for a teradataml DataFrame.
PARAMETERS:
axis:
Optional Argument.
Specifies the value to direct sorting on index or columns.
Values can be either 0 ('rows') OR 1 ('columns'), value as 0 will sort on index (if no index is present then parent DataFrame will be returned)
and value as 1 will sort on columns names (if no index is present then parent DataFrame will be returned with sorted columns) for the DataFrame.
Default value: 0
Types: int
ascending:
Optional Argument.
Specifies a flag to sort columns in either ascending (True) or descending (False).
Default value: True
Types: bool
kind:
Optional Argument.
Specifies a desired algorithm to be used.
Permitted values: 'quicksort', 'mergesort' or 'heapsort'
Default value: 'quicksort'
Types: str
RETURNS:
teradataml DataFrame
RAISES:
TeradataMlException
EXAMPLES:
>>> 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
>>> df.sort_index(0)
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
>>> df.sort_index(1, False) # here 'False' means DESCENDING for respective axis
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
>>> 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