index Property - 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 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_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: Retrieve the index

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

Example: 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']