get() Method | Teradata Python Package - get() Method - Teradata Package for Python

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Language
English (United States)
Last Update
2022-01-14
dita:mapPath
bol1585763678431.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
B700-4006
lifecycle
previous
Product Category
Teradata Vantage

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 1: 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 2: 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 3: 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