Teradata Package for Python Function Reference - squeeze - 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.00
Published
November 2021
Language
English (United States)
Last Update
2021-11-19
lifecycle
previous
Product Category
Teradata Vantage
teradataml.dataframe.dataframe.DataFrame.squeeze = squeeze(self, axis=None)
DESCRIPTION:
    Squeeze one-dimensional axis objects into scalars.
    teradataml DataFrames with a single element are squeezed to a scalar.
    teradataml DataFrames with a single column are squeezed to a Series.
    Otherwise the object is unchanged.
 
    Note: Currently only '1' and 'None' are supported for axis.
          For now with axis = 0, the teradataml DataFrame is returned.
 
PARAMETERS:
    axis:
        Optional Argument.
        A specific axis to squeeze. By default, all axes with
        length equals one are squeezed.
        Permitted Values: 0 or 'index', 1 or 'columns', None
        Default: None
 
RETURNS:
    teradataml DataFrame, teradataml Series, or scalar,
    the projection after squeezing 'axis' or all the axes.
 
RAISES:
    TeradataMlException
 
EXAMPLES:
    >>> load_example_data("dataframe", "admissions_train")
    >>> 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
 
    >>> 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
 
    >>> df = DataFrame.from_query('select gpa, stats from admissions_train where gpa=2.33')
    >>> s = df.squeeze()
    >>> s
        gpa   stats
    0  2.33  Novice
 
    >>> 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