Teradata Package for Python Function Reference | 17.10 - loc - 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.10
Published
April 2022
Language
English (United States)
Last Update
2022-08-19
lifecycle
previous
Product Category
Teradata Vantage
teradataml.geospatial.geodataframe.GeoDataFrame.loc = loc(self)
Access a group of rows and columns by label(s) or a boolean array.
 
VALID INPUTS:
 
    - A single label, e.g. ``5`` or ``'a'``, (note that ``5`` is
    interpreted as a label of the index, it is not interpreted as an
    integer position along the index).
 
    - A list or array of column or index labels, e.g. ``['a', 'b', 'c']``.
 
    - A slice object with labels, e.g. ``'a':'f'``.
    Note that unlike the usual python slices where the stop index is not included, both the
        start and the stop are included
 
    - A conditional expression for row access.
 
    - A boolean array of the same length as the column axis for column access.
 
RETURNS:
    teradataml GeoDataFrame
 
RAISE:
    TeradataMlException
 
EXAMPLES
--------
    >>> load_example_data("geodataframe", ["sample_shapes"])
    >>> geo_dataframe = GeoDataFrame("sample_shapes")
    >>> geo_dataframe = geo_dataframe.select(['skey', 'linestrings', 'polygons'])
    >>> geo_dataframe
                                                                                      linestrings                                                                                                                                                                                                            polygons
    skey
    1006                             LINESTRING (1.35 3.6456 4.5,3.6756 0.23 6.8,0.345 1.756 8.9)                                                                                                                                       POLYGON ((0 0 0,0 0 20,0 20 0,0 20 20,20 0 0,20 0 20,20 20 0,20 20 20,0 0 0))
    1007                                              MULTILINESTRING ((1 1,1 3,6 3),(10 5,20 1))                                                                                                                                               MULTIPOLYGON (((1 1,1 3,6 3,6 0,1 1)),((10 5,10 10,20 10,20 5,10 5)))
    1005                                                           LINESTRING (1 3 6,3 0 6,6 0 1)                                                                               POLYGON ((0 0 0,0 0 20.435,0.0 20.435 0,0.0 20.435 20.435,20.435 0.0 0,20.435 0.0 20.435,20.435 20.435 0,20.435 20.435 20.435,0 0 0))
    1004                                                  LINESTRING (10 20 30,40 50 60,70 80 80)                                                                                                                             POLYGON ((0 0 0,0 10 20,20 20 30,20 10 0,0 0 0),(5 5 5,5 10 10,10 10 10,10 10 5,5 5 5))
    1003                                         LINESTRING (1.35 3.6456,3.6756 0.23,0.345 1.756)                                                                                                                                                             POLYGON ((0.6 0.8,0.6 20.8,20.6 20.8,20.6 0.8,0.6 0.8))
    1001                                                             LINESTRING (1 1,2 2,3 3,4 4)                                                                                                                                                                                 POLYGON ((0 0,0 20,20 20,20 0,0 0))
    1002                                                                 LINESTRING (1 3,3 0,0 1)                                                                                                                                                       POLYGON ((0 0,0 20,20 20,20 0,0 0),(5 5,5 10,10 10,10 5,5 5))
    1009                              MULTILINESTRING ((10 20 30,40 50 60),(70 80 80,90 100 110))                                                                                                            MULTIPOLYGON (((0 0 0,0 20 20,20 20 20,20 0 20,0 0 0)),((50 50 50,50 90 90,90 90 90,90 50 90,50 50 50)))
    1008                    MULTILINESTRING ((1 3,3 0,0 1),(1.35 3.6456,3.6756 0.23,0.345 1.756))                                                                                                                          MULTIPOLYGON (((0 0,0 20,20 20,20 0,0 0)),((0.6 0.8,0.6 20.8,20.6 20.8,20.6 0.8,0.6 0.8)))
    1010  MULTILINESTRING ((1 3 6,3 0 6,6 0 1),(1.35 3.6456 4.5,3.6756 0.23 6.8,0.345 1.756 8.9))  MULTIPOLYGON (((0 0 0,0 0 20,0 20 0,0 20 20,20 0 0,20 0 20,20 20 0,20 20 20,0 0 0)),((0 0 0,0 0 20.435,0.0 20.435 0,0.0 20.435 20.435,20.435 0.0 0,20.435 0.0 20.435,20.435 20.435 0,20.435 20.435 20.435,0 0 0)))
 
    # Example 1: Slice a teradataml GeoDataFrame using a single label.
    >>> geo_dataframe.loc[1004]
                                      linestrings                                                                                 polygons
    skey
    1004  LINESTRING (10 20 30,40 50 60,70 80 80)  POLYGON ((0 0 0,0 10 20,20 20 30,20 10 0,0 0 0),(5 5 5,5 10 10,10 10 10,10 10 5,5 5 5))
 
    # Example 2: Slice a teradataml GeoDataFrame using list of labels. Note using ``[[]]``.
    >>> geo_dataframe.loc[[1004, 1010]]
                                                                                      linestrings                                                                                                                                                                                                            polygons
    skey
    1010  MULTILINESTRING ((1 3 6,3 0 6,6 0 1),(1.35 3.6456 4.5,3.6756 0.23 6.8,0.345 1.756 8.9))  MULTIPOLYGON (((0 0 0,0 0 20,0 20 0,0 20 20,20 0 0,20 0 20,20 20 0,20 20 20,0 0 0)),((0 0 0,0 0 20.435,0.0 20.435 0,0.0 20.435 20.435,20.435 0.0 0,20.435 0.0 20.435,20.435 20.435 0,20.435 20.435 20.435,0 0 0)))
    1004                                                  LINESTRING (10 20 30,40 50 60,70 80 80)                                                                                                                             POLYGON ((0 0 0,0 10 20,20 20 30,20 10 0,0 0 0),(5 5 5,5 10 10,10 10 10,10 10 5,5 5 5))
 
    # Example 3: Slice a teradataml GeoDataFrame using single label both for row and column.
    >>> geo_dataframe.loc[1004, 'linestrings']
                                   linestrings
    0  LINESTRING (10 20 30,40 50 60,70 80 80)
 
    # Example 4: Slice a teradataml GeoDataFrame using single label for row and column access using a tuple.
    >>> geo_dataframe.loc[(1004, 'linestrings')]
                                   linestrings
    0  LINESTRING (10 20 30,40 50 60,70 80 80)
 
    # Example 5: Slice a teradataml GeoDataFrame using with range of labels for row and single label for column.
                 Note that both the start and stop of the slice are included.
    >>> geo_dataframe.loc[1001:1004, 'linestrings']
                                            linestrings
    0  LINESTRING (1.35 3.6456,3.6756 0.23,0.345 1.756)
    1                      LINESTRING (1 1,2 2,3 3,4 4)
    2                          LINESTRING (1 3,3 0,0 1)
    3           LINESTRING (10 20 30,40 50 60,70 80 80)
 
    # Example 6: Slice a teradataml GeoDataFrame with range of labels for both rows and columns.
                 Note that both the start and stop of the range are included.
    >>> geo_dataframe.loc[1001:1004, 'skey':'linestrings']
                                               linestrings
    skey
    1003  LINESTRING (1.35 3.6456,3.6756 0.23,0.345 1.756)
    1001                      LINESTRING (1 1,2 2,3 3,4 4)
    1002                          LINESTRING (1 3,3 0,0 1)
    1004           LINESTRING (10 20 30,40 50 60,70 80 80)
 
    # Example 7: Slice a teradataml GeoDataFrame using empty range for rows and columns.
                 All rows and columns are returned.
    >>> geo_dataframe.loc[:, :]
                                                                                      linestrings                                                                                                                                                                                                            polygons
    skey
    1006                             LINESTRING (1.35 3.6456 4.5,3.6756 0.23 6.8,0.345 1.756 8.9)                                                                                                                                       POLYGON ((0 0 0,0 0 20,0 20 0,0 20 20,20 0 0,20 0 20,20 20 0,20 20 20,0 0 0))
    1007                                              MULTILINESTRING ((1 1,1 3,6 3),(10 5,20 1))                                                                                                                                               MULTIPOLYGON (((1 1,1 3,6 3,6 0,1 1)),((10 5,10 10,20 10,20 5,10 5)))
    1005                                                           LINESTRING (1 3 6,3 0 6,6 0 1)                                                                               POLYGON ((0 0 0,0 0 20.435,0.0 20.435 0,0.0 20.435 20.435,20.435 0.0 0,20.435 0.0 20.435,20.435 20.435 0,20.435 20.435 20.435,0 0 0))
    1004                                                  LINESTRING (10 20 30,40 50 60,70 80 80)                                                                                                                             POLYGON ((0 0 0,0 10 20,20 20 30,20 10 0,0 0 0),(5 5 5,5 10 10,10 10 10,10 10 5,5 5 5))
    1003                                         LINESTRING (1.35 3.6456,3.6756 0.23,0.345 1.756)                                                                                                                                                             POLYGON ((0.6 0.8,0.6 20.8,20.6 20.8,20.6 0.8,0.6 0.8))
    1001                                                             LINESTRING (1 1,2 2,3 3,4 4)                                                                                                                                                                                 POLYGON ((0 0,0 20,20 20,20 0,0 0))
    1002                                                                 LINESTRING (1 3,3 0,0 1)                                                                                                                                                       POLYGON ((0 0,0 20,20 20,20 0,0 0),(5 5,5 10,10 10,10 5,5 5))
    1009                              MULTILINESTRING ((10 20 30,40 50 60),(70 80 80,90 100 110))                                                                                                            MULTIPOLYGON (((0 0 0,0 20 20,20 20 20,20 0 20,0 0 0)),((50 50 50,50 90 90,90 90 90,90 50 90,50 50 50)))
    1008                    MULTILINESTRING ((1 3,3 0,0 1),(1.35 3.6456,3.6756 0.23,0.345 1.756))                                                                                                                          MULTIPOLYGON (((0 0,0 20,20 20,20 0,0 0)),((0.6 0.8,0.6 20.8,20.6 20.8,20.6 0.8,0.6 0.8)))
    1010  MULTILINESTRING ((1 3 6,3 0 6,6 0 1),(1.35 3.6456 4.5,3.6756 0.23 6.8,0.345 1.756 8.9))  MULTIPOLYGON (((0 0 0,0 0 20,0 20 0,0 20 20,20 0 0,20 0 20,20 20 0,20 20 20,0 0 0)),((0 0 0,0 0 20.435,0.0 20.435 0,0.0 20.435 20.435,20.435 0.0 0,20.435 0.0 20.435,20.435 20.435 0,20.435 20.435 20.435,0 0 0)))
 
    # Example 8: Slice a teradataml GeoDataFrame based on a conditional expression.
    >>> geo_dataframe.loc[geo_dataframe['skey'] > 1005]
                                                                                      linestrings                                                                                                                                                                                                            polygons
    skey
    1006                             LINESTRING (1.35 3.6456 4.5,3.6756 0.23 6.8,0.345 1.756 8.9)                                                                                                                                       POLYGON ((0 0 0,0 0 20,0 20 0,0 20 20,20 0 0,20 0 20,20 20 0,20 20 20,0 0 0))
    1007                                              MULTILINESTRING ((1 1,1 3,6 3),(10 5,20 1))                                                                                                                                               MULTIPOLYGON (((1 1,1 3,6 3,6 0,1 1)),((10 5,10 10,20 10,20 5,10 5)))
    1009                              MULTILINESTRING ((10 20 30,40 50 60),(70 80 80,90 100 110))                                                                                                            MULTIPOLYGON (((0 0 0,0 20 20,20 20 20,20 0 20,0 0 0)),((50 50 50,50 90 90,90 90 90,90 50 90,50 50 50)))
    1008                    MULTILINESTRING ((1 3,3 0,0 1),(1.35 3.6456,3.6756 0.23,0.345 1.756))                                                                                                                          MULTIPOLYGON (((0 0,0 20,20 20,20 0,0 0)),((0.6 0.8,0.6 20.8,20.6 20.8,20.6 0.8,0.6 0.8)))
    1010  MULTILINESTRING ((1 3 6,3 0 6,6 0 1),(1.35 3.6456 4.5,3.6756 0.23 6.8,0.345 1.756 8.9))  MULTIPOLYGON (((0 0 0,0 0 20,0 20 0,0 20 20,20 0 0,20 0 20,20 20 0,20 20 20,0 0 0)),((0 0 0,0 0 20.435,0.0 20.435 0,0.0 20.435 20.435,20.435 0.0 0,20.435 0.0 20.435,20.435 20.435 0,20.435 20.435 20.435,0 0 0)))
 
    # Example 9: Slice a teradataml GeoDataFrame based on a conditional expression
    #            and column labels specified.
    >>> geo_dataframe.loc[geo_dataframe['skey'] > 1005, ['skey', 'linestrings']]
                                                                                      linestrings
    skey
    1006                             LINESTRING (1.35 3.6456 4.5,3.6756 0.23 6.8,0.345 1.756 8.9)
    1007                                              MULTILINESTRING ((1 1,1 3,6 3),(10 5,20 1))
    1009                              MULTILINESTRING ((10 20 30,40 50 60),(70 80 80,90 100 110))
    1008                    MULTILINESTRING ((1 3,3 0,0 1),(1.35 3.6456,3.6756 0.23,0.345 1.756))
    1010  MULTILINESTRING ((1 3 6,3 0 6,6 0 1),(1.35 3.6456 4.5,3.6756 0.23 6.8,0.345 1.756 8.9))
 
    # Example 10: Slice a teradataml GeoDataFrame based on a conditional expression
    #             and a range of column labels specified.
    #             Note that both the start and stop of the slice are included.
    >>> geo_dataframe.loc[geo_dataframe['skey'] == 1005, 'skey':'polygons']
                             linestrings                                                                                                                               polygons
    skey
    1005  LINESTRING (1 3 6,3 0 6,6 0 1)  POLYGON ((0 0 0,0 0 20.435,0.0 20.435 0,0.0 20.435 20.435,20.435 0.0 0,20.435 0.0 20.435,20.435 20.435 0,20.435 20.435 20.435,0 0 0))
 
    # Example 11: Slice a teradataml GeoDataFrame based on a conditional expression
    #             and boolean array for column access.
    >>> geo_dataframe.loc[geo_dataframe['skey'] == 1005, [True, False, True]]
                                                                                                                                       polygons
    skey
    1005  POLYGON ((0 0 0,0 0 20.435,0.0 20.435 0,0.0 20.435 20.435,20.435 0.0 0,20.435 0.0 20.435,20.435 20.435 0,20.435 20.435 20.435,0 0 0))
    >>>