Teradata Package for Python Function Reference on VantageCloud Lake - to_pandas - 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_pandas = to_pandas(self, index_column=None, num_rows=99999, all_rows=False, fastexport=False, catch_errors_warnings=False, **kwargs)
- DESCRIPTION:
Returns a Pandas GeoDataFrame for the corresponding teradataml
GeoDataFrame 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 GeoDataFrame'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 GeoDataFrame while creating
Pandas GeoDataFrame.
Default Value: 99999
Types: int
Note:
This argument is ignored if "all_rows" is set to True.
all_rows:
Optional Argument.
Specifies whether all rows from teradataml GeoDataFrame should be
retrieved while creating Pandas GeoDataFrame.
Default Value: False
Types: bool
fastexport:
Optional Argument.
Specifies whether fastexport protocol should be used while
converting teradataml GeoDataFrame to a Pandas GeoDataFrame. If the
argument is set to True, fastexport wire protocol is used
internally for data transfer. By default, fastexport protocol will not be
used while converting teradataml GeoDataFrame to a Pandas GeoDataFrame.
When set to None, the approach is decided based on the number of rows
requested by the user for extraction.
If requested number of rows are greater than or equal to 100000,
then fastexport is used, otherwise regular mode is used for data
extraction.
Note:
1. Teradata recommends to use FastExport when number of rows
in teradataml GeoDataFrame 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 GeoDataFrame.groupby() and
GeoDataFrame.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
catch_errors_warnings:
Optional Argument.
Specifies whether to catch errors/warnings(if any) raised by
fastexport protocol while converting teradataml GeoDataFrame to
Pandas GeoDataFrame. When this is set to True and fastexport is used,
to_pandas() returns a tuple containing:
a. Pandas GeoDataFrame.
b. Errors(if any) in a list thrown by fastexport.
c. Warnings(if any) in a list thrown by fastexport.
When set to False and fastexport is used, prints the fastexport
errors/warnings to the standard output, if there are any.
Note:
This argument is ignored if "fastexport" is set to False.
Default Value: False
Types: bool
kwargs:
Optional Argument.
Specifies keyword arguments. Arguments "coerce_float" and
"parse_dates" can be passed as keyword arguments.
* "coerce_float" specifies a boolean to for attempting to
convert non-string, non-numeric objects to floating point.
* "parse_dates" specifies columns to parse as dates.
Note:
For additional information about "coerce_float" and
"parse_date" arguments please refer to:
https://pandas.pydata.org/docs/reference/api/pandas.read_sql.html
RETURNS:
When "catch_errors_warnings" is set to True and if protocol used for
data transfer is fastexport, then the function returns a tuple
containing:
a. Pandas GeoDataFrame.
b. Errors, if any, thrown by fastexport in a list of strings.
c. Warnings, if any, thrown by fastexport in a list of strings.
Only Pandas GeoDataFrame otherwise.
Note:
Column types of the resulting Pandas GeoDataFrame depends on
pandas.read_sql_query().
RAISES:
TeradataMlException
EXAMPLES:
>>> load_example_data("geodataframe","sample_streets")
>>> df = GeoDataFrame("sample_streets")
>>> df
street_name street_shape
skey
1 Coast Blvd LINESTRING (12 12,18 17)
1 Main Street LINESTRING (2 2,3 2,4 1)
>>>
>>> pandas_df = df.to_pandas()
>>> pandas_df
street_name street_shape
skey
1 Main Street LINESTRING (2 2,3 2,4 1)
1 Coast Blvd LINESTRING (12 12,18 17)
>>>
>>> pandas_df = df.to_pandas(index_column = 'skey')
>>> pandas_df
street_name street_shape
skey
1 Main Street LINESTRING (2 2,3 2,4 1)
1 Coast Blvd LINESTRING (12 12,18 17)
>>>
>>> pandas_df = df.to_pandas(index_column = 'street_shape')
>>> pandas_df
skey street_name
street_shape
LINESTRING (2 2,3 2,4 1) 1 Main Street
LINESTRING (12 12,18 17) 1 Coast Blvd
>>>
>>> pandas_df = df.to_pandas(index_column = ['skey', 'street_name'])
>>> pandas_df
street_shape
skey street_name
1 Main Street LINESTRING (2 2,3 2,4 1)
Coast Blvd LINESTRING (12 12,18 17)
>>>
>>> pandas_df = df.to_pandas(index_column = 'skey', num_rows = 1)
>>> pandas_df
street_name street_shape
skey
1 Coast Blvd LINESTRING (12 12,18 17)
>>>
>>> pandas_df = df.to_pandas(all_rows = True)
>>> pandas_df
street_name street_shape
skey
1 Main Street LINESTRING (2 2,3 2,4 1)
1 Coast Blvd LINESTRING (12 12,18 17)
>>>