Use the squeeze() method to squeeze one-dimensional axis objects into a scalar for teradataml DataFrames with a single element, or a Series object for a teradataml DataFrame with a single column.
The teradataml DataFrame is returned unchanged when both dimensions are greater than one.
The axis parameter specifies the axis along which the squeeze operation is to be attempted. The possible values are:
- 1 or 'columns': Return Series object if number of columns equals one.
- 0 or 'index' : Return the unchanged teradataml DataFrame object.
Examples Prerequisite
Assume the table "admissions_train" exists and its index column is id. And a DataFrame "df" is created based on this table using the command:
>>> df = DataFrame("admissions_train")
>>> df masters gpa stats programming admitted id 22 yes 3.46 Novice Beginner 0 36 no 3.00 Advanced Novice 0 15 yes 4.00 Advanced Advanced 1 38 yes 2.65 Advanced Beginner 1 5 no 3.44 Novice Novice 0 17 no 3.83 Advanced Advanced 1 34 yes 3.85 Advanced Beginner 0 13 no 4.00 Advanced Novice 1 26 yes 3.57 Advanced Advanced 1 19 yes 1.98 Advanced Advanced 0
Example: Squeeze a teradataml DataFrame with both dimension greater than one.
>>> df.squeeze() masters gpa stats programming admitted id 22 yes 3.46 Novice Beginner 0 36 no 3.00 Advanced Novice 0 15 yes 4.00 Advanced Advanced 1 38 yes 2.65 Advanced Beginner 1 5 no 3.44 Novice Novice 0 17 no 3.83 Advanced Advanced 1 34 yes 3.85 Advanced Beginner 0 13 no 4.00 Advanced Novice 1 26 yes 3.57 Advanced Advanced 1 19 yes 1.98 Advanced Advanced 0
Example: Squeeze a single-column teradataml DataFrame.
>>> gpa = df.select(["gpa"]) >>> gpa.squeeze() 0 4.00 1 2.33 2 3.46 3 3.83 4 4.00 5 2.65 6 3.57 7 3.44 8 3.85 9 3.95 Name: gpa, dtype: float64
>>> gpa.squeeze(axis = 1) 0 3.46 1 3.00 2 4.00 3 2.65 4 3.44 5 3.83 6 3.85 7 4.00 8 3.57 9 1.98 Name: gpa, dtype: float64
>>> gpa.squeeze(axis = 0) gpa 0 3.46 1 3.00 2 4.00 3 2.65 4 3.44 5 3.83 6 3.85 7 4.00 8 3.57 9 1.98
Example: Squeeze a teradataml DataFrame with multiple columns and a single row.
>>> df = DataFrame.from_query('select gpa, stats from admissions_train where gpa=2.33') >>> df gpa stats 0 2.33 Novice
>>> s = df.squeeze() >>> s gpa stats 0 2.33 Novice
Example: Squeeze a teradataml DataFrame with a single element.
>>> single_gpa = DataFrame.from_query('select gpa from admissions_train where gpa=2.33') >>> single_gpa gpa 0 2.33
>>> single_gpa.squeeze() 2.33
>>> single_gpa.squeeze(axis = 1) 0 2.33 Name: gpa, dtype: float64
>>> single_gpa.squeeze(axis = 0) gpa 0 2.33