Teradata Package for Python Function Reference on VantageCloud Lake - to_csv - 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 on VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Package for Python
Release Number
20.00.00.03
Published
December 2024
ft:locale
en-US
ft:lastEdition
2024-12-19
dita:id
TeradataPython_FxRef_Lake_2000
Product Category
Teradata Vantage
teradataml.geospatial.geodataframe.GeoDataFrame.to_csv = to_csv(self, csv_file, num_rows=99999, all_rows=False, fastexport=False, sep=',', quotechar='"', catch_errors_warnings=False, **kwargs)
DESCRIPTION:
    Export data to CSV from teradataml DataFrame with or
    without FastExport protocol.
 
PARAMETERS:
    csv_file:
        Required Argument.
        Specifies the name of CSV file to export the data into.
        Types: str
 
    num_rows:
        Optional Argument.
        Specifies the number of rows to export.
        Note:
            This argument is ignored if "all_rows" is set to True.
        Default Value: 99999
        Types: int
 
    all_rows:
        Optional Argument.
        Specifies whether all rows should be exported to CSV or not.
        Default Value: False
        Types: bool
 
    fastexport:
        Optional Argument.
        Specifies whether FastExport protocol should be used or not while
        exporting data. When set to True, data is exported using FastExport
        protocol, otherwise FastExport protocol is not used, which is default.
        When set to None, the approach is decided based on the number of rows
        to be exported.
        Notes:
            1. Teradata recommends to use FastExport when number of rows
               in teradataml DataFrame are atleast 100,000. To extract
               lesser rows ignore this option and go with regular
               approach. FastExport opens multiple data transfer connections
               to the database.
            2. FastExport does not support all Teradata Database data types.
               For example, tables with BLOB and CLOB type columns cannot
               be extracted.
            3. FastExport cannot be used to extract data from a
               volatile or temporary table.
            4. For best efficiency, do not use DataFrame.groupby() and
               DataFrame.sort() with FastExport.
 
        For additional information about FastExport protocol through
        teradatasql driver, please refer to FASTEXPORT section of
        https://pypi.org/project/teradatasql/#FastExport driver documentation.
        Default Value: False
        Types: bool
 
    sep:
        Optional Argument.
        Specifies a single character string used to separate fields in a CSV file.
        Default Value: ","
        Notes:
            1. "sep" cannot be line feed ('\n') or carriage return ('\r').
            2. "sep" should not be same as "quotechar".
            3. Length of "sep" argument should be 1.
        Types: String
 
    quotechar:
        Optional Argument.
        Specifies a single character string used to quote fields in a CSV file.
        Default Value: """
        Notes:
            1. "quotechar" cannot be line feed ('\n') or carriage return ('\r').
            2. "quotechar" should not be same as "sep".
            3. Length of "quotechar" argument should be 1.
        Types: String
 
    catch_errors_warnings:
        Optional Argument.
        Specifies whether to catch errors/warnings (if any) raised by
        FastExport protocol while exporting data.
        Note:
            This argument is ignored if "fastexport" is set to False.
        Default Value: False
        Types: bool
 
    kwargs:
        Optional Argument.
        Specifies keyword arguments. Argument "open_sessions" can be
        passed as keyword arguments.
            * "open_sessions" specifies the number of Teradata data transfer
              sessions to be opened for fastexport. This argument is only
              applicable in fastexport mode.
 
        Note:
            If "open_sessions" argument is not provided, the default value
               is the smaller of 8 or the number of AMPs avaialble.
               For additional information about number of Teradata data-transfer
               sessions opened during fastexport, please refer to:
               https://pypi.org/project/teradatasql/#FastExport
 
 
RETURNS:
    When FastExport protocol is used and "catch_errors_warnings" is set to True,
    then the function returns a tuple containing:
        a. Errors, if any, thrown by fastexport in a list of strings.
        b. Warnings, if any, thrown by fastexport in a list of strings.
 
RAISES:
    TeradataMlException
 
EXAMPLES:
 
    # Create a teradataml DataFrame.
    >>> 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
    ...
 
    # Example 1: Export data from teradataml DataFrame into CSV,
    #            with only required argument.
    >>> df.to_csv("export_to_csv_1.csv")
       Data is successfully exported into export_to_csv_1.csv
 
    # Example 2: Export all rows from teradataml DataFrame into CSV
    #            using FastExport protocol.
    >>> df.to_csv("export_to_csv_2.csv", all_rows=True, fastexport=True)
       Data is successfully exported into export_to_csv_2.csv
 
    # Example 3: Export 20 rows from teradataml DataFrame into CSV.
    >>> df.to_csv("export_to_csv_3.csv", num_rows=20)
       Data is successfully exported into export_to_csv_3.csv
 
    # Example 4: Export data from teradataml DataFrame into CSV using
    #            FastExport protocol by opening one Teradata data
    #            transfer session. Save errors and warnings
    #            thrown by fastexport.
    >>> err, warn = df.to_csv("export_to_csv_4.csv", fastexport=True,
                              catch_errors_warnings=True, open_sessions=1 )
       Data is successfully exported into export_to_csv_4.csv
    >>>err
       []
    >>>warn
       []
 
    # Example 5: Export data from teradataml DataFrame into CSV
    #            file with '|' as field separator and single quote(')
    #            as field quote character.
    >>> df.to_csv("export_to_csv_5.csv", sep="|", quotechar="'" )
       Data is successfully exported into export_to_csv_5.csv