get_values() 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_values() function to retrieve all values (only) present in a teradataml DataFrame.

The values are retrieved as per a numpy.ndarray representation of the teradataml DataFrame. This format is equivalent to the get_values() representation of a Pandas DataFrame.

An optional integer valued parameter num_rows allows the user to specify the number of rows to retrieve values for from the teradataml DataFrame.

Example Prerequisite

>>> 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: Retrieves values present in a teradataml DataFrame

>>> vals = df.get_values()
>>> vals
 
array([['yes', 4.0, 'advanced', 'advanced', 1],
      ['yes', 3.45, 'advanced', 'advanced', 0],
      ['yes', 3.5, 'advanced', 'beginner', 1],
      ['yes', 4.0, 'novice', 'beginner', 0],
                    . . .
      ['no', 3.68, 'novice', 'beginner', 1],
      ['yes', 3.5, 'beginner', 'advanced', 1],
      ['yes', 3.79, 'advanced', 'novice', 0],
      ['no', 3.0, 'advanced', 'novice', 0],
      ['yes', 1.98, 'advanced', 'advanced', 0]], dtype=object)

Example: Retrieve values for a given number of rows from a teradataml DataFrame

>>> vals = df1.get_values(num_rows = 3)
>>> vals
 
array([['yes', 4.0, 'advanced', 'advanced', 1],
        ['yes', 3.45, 'advanced', 'advanced', 0],
        ['yes', 3.5, 'advanced', 'beginner', 1]], dtype=object)

Example: Access specific values from the entire set received

# Retrieve all values from an entire row (for example, the first row):
>>> vals[0]
array(['yes', 4.0, 'advanced', 'advanced', 1], dtype=object)
# Specify a range to retrieve values from  a subset of rows (For example, first 3 rows):
>>> vals[0:3]
array([['yes', 4.0, 'advanced', 'advanced', 1],
       ['yes', 3.45, 'advanced', 'advanced', 0],
       ['yes', 3.5, 'advanced', 'beginner', 1]], dtype=object)
# Retrieve all values from an entire column (For example, the first column):
>>> vals[:, 0]
array(['yes', 'yes', 'yes', 'yes', 'yes', 'no', 'yes', 'yes', 'yes',
       'yes', 'no', 'no', 'yes', 'yes', 'no', 'yes', 'no', 'yes', 'no',
       'no', 'no', 'no', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes',
       'yes', 'yes', 'no', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no','yes'], dtype=object)
# Retrieve a single value from a given row and column (For example, 3rd row, and 2nd column):           
>>> vals[2,1]
3.5
  • Row and column indexing starts from 0, so the first column = index 0, second column = index 1, and so on.
  • When a Pandas DataFrame is saved to Teradata Database and then retrieved back as a teradataml DataFrame, the get_values() method on a Pandas DataFrame, and the corresponding teradataml DataFrames have the following type differences:
    • teradataml DataFrame get_values() retrieves 'bool' type Pandas DataFrame values ('True' or 'False') as BYTEINTS ('1' or '0');
    • teradataml DataFrame get_values() retrieves 'Timedelta' type Pandas DataFrame values as equivalent values in seconds.