Teradata Python Package Function Reference - to_pandas - Teradata Python Package - Look here for syntax, methods and examples for the functions included in the Teradata Python Package.

Teradata® Python Package Function Reference

Product
Teradata Python Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-07-17
lifecycle
previous
Product Category
Teradata Vantage
teradataml.dataframe.dataframe.DataFrame.to_pandas = to_pandas(self, index_column=None, num_rows=99999)
DESCRIPTION:
    Returns a Pandas DataFrame for the corresponding teradataml DataFrame Object.
 
PARAMETERS:
    index_column:
        Optional Argument.
        Specifies column(s) to be used as Pandas index.
        When the argument is provided, the specified column is used as the Pandas index.
        Otherwise, the teradataml DataFrame's index (if exists) is used as the Pandas index
        or the primary index of the table on Vantage is used as the Pandas index.
        The default integer index is used if none of the above indexes exists.
        Default Value: Integer index
        Types: str OR list of Strings (str)
 
    num_rows:
        Optional Argument.
        The number of rows to retrieve from DataFrame while creating Pandas Dataframe.
        Default Value: 99999
        Types: int
 
RETURNS:
    Pandas DataFrame
 
    Note:
        Column types of the resulting Pandas DataFrame depends on pandas.read_sql_query(). 
 
RAISES:
    TeradataMlException
 
EXAMPLES:
 
    Teradata supports the following formats:
 
    A] No parameter(s): df.to_pandas()
    B] Single index_column parameter: df.to_pandas(index_column = "col1")
    C] Multiple index_column (list) parameters: df.to_pandas(index_column = ['col1', 'col2'])
    D] Only num_rows parameter specified:  df.to_pandas(num_rows = 100)
    E] Both index_column & num_rows specified: df.to_pandas(index_column = 'col1', num_rows = 100)
 
    Column names ("col1", "col2"..) are strings representing Teradata Vantage table Columns.
    It supports all standard Teradata data types for columns: INTEGER, VARCHAR(5), FLOAT etc.
    df is a Teradata DataFrame object: df = DataFrame.from_table('admissions_train')
 
    >>> load_example_data("dataframe","admissions_train")
    >>> df = DataFrame("admissions_train")
    >>> df
       masters   gpa     stats programming admitted
    id
    22     yes  3.46    Novice    Beginner        0
    37      no  3.52    Novice      Novice        1
    35      no  3.68    Novice    Beginner        1
    12      no  3.65    Novice      Novice        1
    4      yes  3.50  Beginner      Novice        1
    38     yes  2.65  Advanced    Beginner        1
    27     yes  3.96  Advanced    Advanced        0
    39     yes  3.75  Advanced    Beginner        0
    7      yes  2.33    Novice      Novice        1
    40     yes  3.95    Novice    Beginner        0
    >>> pandas_df = df.to_pandas()
    >>> pandas_df
       masters   gpa     stats programming  admitted
    id
    15     yes  4.00  Advanced    Advanced         1
    14     yes  3.45  Advanced    Advanced         0
    31     yes  3.50  Advanced    Beginner         1
    29     yes  4.00    Novice    Beginner         0
    23     yes  3.59  Advanced      Novice         1
    21      no  3.87    Novice    Beginner         1
    17      no  3.83  Advanced    Advanced         1
    34     yes  3.85  Advanced    Beginner         0
    13      no  4.00  Advanced      Novice         1
    32     yes  3.46  Advanced    Beginner         0
    11      no  3.13  Advanced    Advanced         1
    ...
 
    >>> pandas_df = df.to_pandas(index_column = 'id')
    >>> pandas_df
       masters   gpa     stats programming  admitted
    id
    15     yes  4.00  Advanced    Advanced         1
    14     yes  3.45  Advanced    Advanced         0
    31     yes  3.50  Advanced    Beginner         1
    29     yes  4.00    Novice    Beginner         0
    23     yes  3.59  Advanced      Novice         1
    21      no  3.87    Novice    Beginner         1
    17      no  3.83  Advanced    Advanced         1
    34     yes  3.85  Advanced    Beginner         0
    13      no  4.00  Advanced      Novice         1
    32     yes  3.46  Advanced    Beginner         0
    11      no  3.13  Advanced    Advanced         1
    28      no  3.93  Advanced    Advanced         1
    ...
 
    >>> pandas_df = df.to_pandas(index_column = 'gpa')
    >>> pandas_df
          id masters     stats programming  admitted
    gpa
    4.00  15     yes  Advanced    Advanced         1
    3.45  14     yes  Advanced    Advanced         0
    3.50  31     yes  Advanced    Beginner         1
    4.00  29     yes    Novice    Beginner         0
    3.59  23     yes  Advanced      Novice         1
    3.87  21      no    Novice    Beginner         1
    3.83  17      no  Advanced    Advanced         1
    3.85  34     yes  Advanced    Beginner         0
    4.00  13      no  Advanced      Novice         1
    3.46  32     yes  Advanced    Beginner         0
    3.13  11      no  Advanced    Advanced         1
    3.93  28      no  Advanced    Advanced         1
    ...
 
    >>> pandas_df = df.to_pandas(index_column = ['masters', 'gpa'])
    >>> pandas_df
                  id     stats programming  admitted
    masters gpa
    yes     4.00  15  Advanced    Advanced         1
            3.45  14  Advanced    Advanced         0
            3.50  31  Advanced    Beginner         1
            4.00  29    Novice    Beginner         0
            3.59  23  Advanced      Novice         1
    no      3.87  21    Novice    Beginner         1
            3.83  17  Advanced    Advanced         1
    yes     3.85  34  Advanced    Beginner         0
    no      4.00  13  Advanced      Novice         1
    yes     3.46  32  Advanced    Beginner         0
    no      3.13  11  Advanced    Advanced         1
            3.93  28  Advanced    Advanced         1
    ...
 
    >>> pandas_df = df.to_pandas(index_column = 'gpa', num_rows = 3)
    >>> pandas_df
          id masters   stats programming  admitted
    gpa
    3.46  22     yes  Novice    Beginner         0
    2.33   7     yes  Novice      Novice         1
    3.95  40     yes  Novice    Beginner         0