Teradata Package for Python Function Reference on VantageCloud Lake - __getitem__ - 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.dataframe.dataframe.DataFrame.__getitem__ = __getitem__(self, key)
- Return a column from the DataFrame or filter the DataFrame using an expression
or select columns from a DataFrame using the specified list of columns..
The following operators are supported:
comparison: ==, !=, <, <=, >, >=
boolean: & (and), | (or), ~ (not), ^ (xor)
Operands can be Python literals and instances of ColumnExpressions from the DataFrame
PARAMETERS:
key:
Required Argument.
Specifies the column name(s) of filter expression (ColumnExpression).
Specify key as:
* a string - to get the column of a teradataml DataFrame, i.e., a ColumnExpression.
* list of strings - to select columns of a teradataml DataFrame.
* filter expression - to filter the data from teradataml DataFrame using the specified expression.
Types: str or list of strings or ColumnExpression
RETURNS:
DataFrame or ColumnExpression instance
RAISES:
1. KeyError - If key is not found
2. ValueError - When columns of different dataframes are given in ColumnExpression.
EXAMPLES:
# Load the example data.
load_example_data("teradataml", ["titanic"])
# Create teradataml DataFrame object.
df = DataFrame("titanic")
# Filter the DataFrame df.
df[df.sibsp > df.parch]
df[df.age >= 50]
df[df.sex == "female"]
df[1 != df.parch]
df[~(1 < df.parch)]
df[(df.parch > 0) & (df.sibsp > df.parch)]
# Retrieve column cabin from df.
df["cabin"]
# Select columns using list of column names from a teradataml DataFrame..
df[["embarked", "age", "cabin"]]