index Property | Teradata Python Package - index Property - Teradata Package for Python

Teradata® Package for Python User Guide

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00
Published
December 2024
ft:locale
en-US
ft:lastEdition
2025-01-23
dita:mapPath
nvi1706202040305.ditamap
dita:ditavalPath
plt1683835213376.ditaval
dita:id
rkb1531260709148
lifecycle
latest
Product Category
Teradata Vantage
Use the index property to retrieve the index of the teradataml DataFrame, which corresponds to the primary index of the underlying Table or View.

In case the index is explicitly set using the DataFrame.set_index() method or by passing the index_label parameter while creating the teradataml DataFrame, the property will return the value set by the user.

Example Prerequisite

Load the admissions_train dataset and create a teradataml DataFrame out of it.

>>> load_example_data("dataframe","admissions_train")
>>> df = DataFrame("admissions_train")
>>> df
   masters   gpa     stats programming  admitted
id
5       no  3.44    Novice      Novice         0
3       no  3.70    Novice    Beginner         1
1      yes  3.95  Beginner    Beginner         0
20     yes  3.90  Advanced    Advanced         1
8       no  3.60  Beginner    Advanced         1
25      no  3.96  Advanced    Advanced         1
18     yes  3.81  Advanced    Advanced         1
24      no  1.87  Advanced      Novice         1
26     yes  3.57  Advanced    Advanced         1
38     yes  2.65  Advanced    Beginner         1

Example 1: Retrieve the index

>>> # Get the index_label
>>> df.index
['id']

Example 2: Set the index using the set_index() method and then retrieve the index

Set the index for the teradataml DataFrame using the set_index() method.

>>> # Set new index_label
>>> df = df.set_index(['id', 'masters'])
>>> df
             gpa     stats programming  admitted
id masters
5  no       3.44    Novice      Novice         0
3  no       3.70    Novice    Beginner         1
1  yes      3.95  Beginner    Beginner         0
17 no       3.83  Advanced    Advanced         1
13 no       4.00  Advanced      Novice         1
32 yes      3.46  Advanced    Beginner         0
11 no       3.13  Advanced    Advanced         1
9  no       3.82  Advanced    Advanced         1
34 yes      3.85  Advanced    Beginner         0
24 no       1.87  Advanced      Novice         1

Retrieve the index.

>>> # Get the index_label
>>> df.index
['id', 'masters']