Teradata Package for Python Function Reference | 20.00 - set_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.geospatial.geodataframe.GeoDataFrame.set_index = set_index(self, keys, drop=True, append=False)
- DESCRIPTION:
Assigns one or more existing columns as the new index to a teradataml GeoDataFrame.
PARAMETERS:
keys:
Required Argument.
Specifies the column name or a list of column names to use as the GeoDataFrame index.
Types: str OR list of Strings (str)
drop:
Optional Argument.
Specifies whether or not to display the column(s) being set as index as
teradataml GeoDataFrame columns anymore.
When drop is True, columns are set as index and not displayed as columns.
When drop is False, columns are set as index; but also displayed as columns.
Note: When the drop argument is set to True, the column being set as index does not cease to
be a part of the underlying table upon which the teradataml GeoDataFrame is based off.
A column that is dropped while being set as an index is merely not used for display
purposes anymore as a column of the teradataml GeoDataFrame.
Default Value: True
Types: bool
append:
Optional Argument.
Specifies whether or not to append requested columns to the existing index.
` When append is False, replaces existing index.
When append is True, retains both existing & currently appended index.
Default Value: False
Types: bool
RETURNS:
teradataml GeoDataFrame
RAISES:
TeradataMlException
EXAMPLES:
>>> load_example_data("geodataframe","sample_cities")
>>> df = GeoDataFrame("sample_cities")
>>> df.sort('skey')
city_name city_shape
skey
0 Oceanville POLYGON ((1 1,1 3,6 3,6 0,1 1))
1 Seaside POLYGON ((10 10,10 20,20 20,20 15,10 10))
>>>
# Set new index.
>>> df.set_index('city_shape').sort('skey')
skey city_name
city_shape
POLYGON ((1 1,1 3,6 3,6 0,1 1)) 0 Oceanville
POLYGON ((10 10,10 20,20 20,20 15,10 10)) 1 Seaside
>>>
# Set multiple indexes using list of columns
>>> df.set_index(['city_name', 'skey']).sort('skey')
city_shape
city_name skey
Oceanville 0 POLYGON ((1 1,1 3,6 3,6 0,1 1))
Seaside 1 POLYGON ((10 10,10 20,20 20,20 15,10 10))
>>>
# Append to new index to the existing set of index.
>>> df.set_index(['city_name', 'skey'], drop = False, append = True).sort('skey')
city_shape
city_name skey
Oceanville 0 POLYGON ((1 1,1 3,6 3,6 0,1 1))
Seaside 1 POLYGON ((10 10,10 20,20 20,20 15,10 10))
>>>