
我知道我可以使用 str.contains() 来检查列中是否包含字符串,例如:
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)
)
)我想要的是比赛的确切起始位置,而不仅仅是一个布尔值,如:
import re x = re.search(r"pony","my little pony") print(x.start(),x.end())
我怎样才能做到这一点?
您可以使用series.str.find()方法:
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)
)
)
以上就是如何在极坐标上获取 str.contains() 中的字符串匹配起始位置?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号