Nota
L-aċċess għal din il-paġna jeħtieġ l-awtorizzazzjoni. Tista’ tipprova tidħol jew tibdel id-direttorji.
L-aċċess għal din il-paġna jeħtieġ l-awtorizzazzjoni. Tista’ tipprova tibdel id-direttorji.
Locate the position of the first occurrence of substr column in the given string. Returns null if either of the arguments are null.
The position is not zero based, but 1 based index. Returns 0 if substr could not be found in str.
For the corresponding Databricks SQL function, see instr function.
Syntax
from pyspark.sql import functions as dbf
dbf.instr(str=<str>, substr=<substr>)
Parameters
| Parameter | Type | Description |
|---|---|---|
str |
pyspark.sql.Column or str |
target column to work on. |
substr |
pyspark.sql.Column or literal string |
substring to look for. |
Returns
pyspark.sql.Column: location of the first occurrence of the substring as integer.
Examples
from pyspark.sql import functions as dbf
df = spark.createDataFrame([("abcd",), ("xyz",)], ["s",])
df.select("*", dbf.instr(df.s, "b")).show()
df = spark.createDataFrame([("abcd",), ("xyz",)], ["s",])
df.select("*", dbf.instr("s", dbf.lit("abc").substr(0, 2))).show()