get() Method

Teradata® Python Package User Guide

brand
Teradata Vantage
prodname
Teradata Python Package
vrm_release
16.20
category
User Guide
featnum
B700-4006-098K

Use the get() function to retrieve required columns from a teradataml DataFrame.

The function takes a key representing a column name as an argument and returns a new DataFrame with the the appropriate columns. The key can be a single column name or a list of column names.

Multicolumn retrieval of the same column such as df.get(['col1', 'col1']) is not supported.

Examples Prerequisite

Assume a teradataml DataFrame is created based on the table "admissions_train".
>>> df = DataFrame("admissions_train")

>>> df
    masters   gpa     stats programming admitted
id
5        no  3.44    novice      novice        0
7       yes  2.33    novice      novice        1
22      yes  3.46    novice    beginner        0
17       no  3.83  advanced    advanced        1
13       no  4.00  advanced      novice        1
19      yes  1.98  advanced    advanced        0
36       no  3.00  advanced      novice        0
15      yes  4.00  advanced    advanced        1
34      yes  3.85  advanced    beginner        0
40      yes  3.95    novice    beginner        0

Example: Retrieve a single column

This example retrieves a single column "id" from the table "admissions_train". Column "id" is the index column.
>>>df.get("id")
Empty DataFrame
Columns: []
Index: [22, 34, 13, 19, 15, 38, 26, 5, 36, 17]

Example: Retrieve multiple columns using a list of columns names

Use a list of columns names for multicolumn retrieval.
>>>df.get(["id", "masters", "gpa"])
    masters   gpa
id
5        no  3.44
36       no  3.00
15      yes  4.00
17       no  3.83
13       no  4.00
40      yes  3.95
7       yes  2.33
22      yes  3.46
34      yes  3.85
19      yes  1.98

Example: Retrieve multiple columns using a list of list of columns names

Use a list of list of columns names for multicolumn retrieval.
>>> df.get([['id', 'masters', 'gpa']])
    masters   gpa
id
5        no  3.44
34      yes  3.85
13       no  4.00
40      yes  3.95
22      yes  3.46
19      yes  1.98
36       no  3.00
15      yes  4.00
7       yes  2.33
17       no  3.83