Teradata Package for Python Function Reference on VantageCloud Lake - startswith - 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
- Language
- English (United States)
- Last Update
- 2024-12-19
- dita:id
- TeradataPython_FxRef_Lake_2000
- Product Category
- Teradata Vantage
- teradataml.dataframe.sql.DataFrameColumn.startswith = startswith(self, other)
- DESCRIPTION:
Function to check whether the column value starts with the specified value or not.
PARAMETERS:
other:
Required Argument.
Specifies a string literal or ColumnExpression to match.
Types: str OR ColumnExpression
RETURNS:
ColumnExpression.
EXAMPLES:
>>> load_example_data("ntree", "employee_table")
>>> df = DataFrame("employee_table")
>>> df
emp_name mgr_id mgr_name
emp_id
200 Pat 100.0 Don
300 Donna 100.0 Don
400 Kim 200.0 Pat
500 Fred 400.0 Kim
100 Don NaN NA
# Example 1: Find out the employees whose name starts with their managers name.
>>> df[df.emp_name.startswith(df.mgr_name)]
emp_name mgr_id mgr_name
emp_id
300 Donna 100 Don
# Example 2: Find out the employees whose manager name starts with Don.
>>> df[df.mgr_name.startswith('Don')]
emp_name mgr_id mgr_name
emp_id
300 Donna 100 Don
200 Pat 100 Don
# Example 3: Create a new column with values as
# 1, if employees manager name starts with 'Don'.
# 0, else.
>>> df.assign(new_col=case_when((df.mgr_name.startswith('Don').expression, 1), else_=0))
emp_name mgr_id mgr_name new_col
emp_id
300 Donna 100.0 Don 1
500 Fred 400.0 Kim 0
100 Don NaN NA 0
400 Kim 200.0 Pat 0
200 Pat 100.0 Don 1