Home >Backend Development >Python Tutorial >How to get the starting position of a string match in str.contains() in polar coordinates?
I know I can use str.contains() to check if a column contains a string, for example:
import polars as pl df = pl.dataframe({"a": ["my name is bob","my little pony, my little pony"]}) (df.with_columns(bbb = pl.col('a').str.slice(1,10000).str.contains(pl.col('a').str.slice(0,10), literal=true) ) )
What I want is the exact starting position of the race, not just a boolean like:
import re x = re.search(r"pony","my little pony") print(x.start(),x.end())
How can I do this?
You can use series.str.find()
Method:
import polars as pl df = pl.DataFrame({"a": ["my name is Bob","my little pony, my little pony"]}) df.with_columns( bbb=pl.col('a').str.slice(1,10000).str.find( pl.col('a').str.slice(0,10), literal=True) ) )
The above is the detailed content of How to get the starting position of a string match in str.contains() in polar coordinates?. For more information, please follow other related articles on the PHP Chinese website!