Teradata Package for Python Function Reference | 17.10 - get_values - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.
Teradata® Package for Python Function Reference
- Product
- Teradata Package for Python
- Release Number
- 17.10
- Published
- April 2022
- Language
- English (United States)
- Last Update
- 2022-08-19
- lifecycle
- previous
- Product Category
- Teradata Vantage
- teradataml.dataframe.dataframe.DataFrame.get_values = get_values(self, num_rows=99999)
- DESCRIPTION:
Retrieves all values (only) present in a teradataml DataFrame.
Values are retrieved as per a numpy.ndarray representation of a teradataml DataFrame.
This format is equivalent to the get_values() representation of a Pandas DataFrame.
PARAMETERS:
num_rows:
Optional Argument.
Specifies the number of rows to retrieve values for from a teradataml DataFrame.
The num_rows parameter specified needs to be an integer value.
Default Value: 99999
Types: int
RETURNS:
Numpy.ndarray representation of a teradataml DataFrame
RAISES:
TeradataMlException
EXAMPLES:
>>> load_example_data("dataframe","admissions_train")
>>> df1 = DataFrame.from_table('admissions_train')
>>> df1
masters gpa stats programming admitted
id
15 yes 4.00 Advanced Advanced 1
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
38 yes 2.65 Advanced Beginner 1
26 yes 3.57 Advanced Advanced 1
5 no 3.44 Novice Novice 0
34 yes 3.85 Advanced Beginner 0
40 yes 3.95 Novice Beginner 0
# Retrieve all values from the teradataml DataFrame
>>> vals = df1.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)
# Retrieve values for a given number of rows from the 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)
# Access specific values from the entire set received as per below:
# Retrieve all values from an entire row (for example, the first row):
>>> vals[0]
array(['yes', 4.0, 'Advanced', 'Advanced', 1], dtype=object)
# Alternatively, 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)
# Alternatively, 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)
# Alternatively, retrieve a single value from a given row and column (For example, 3rd row, and 2nd column):
>>> vals[2,1]
3.5
Note:
1) Row and column indexing starts from 0, so the first column = index 0, second column = index 1, and so on...
2) When a Pandas DataFrame is saved to Teradata Vantage & 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/False) as BYTEINTS (1/0)
- teradataml DataFrame get_values() retrieves 'Timedelta' type Pandas DataFrame values as equivalent values in seconds.