gpt4 book ai didi

python - PANDAS 在一列字符串中找到确切的单词和单词(多个)之前的单词并附加它,python 中的新列

转载 作者:太空宇宙 更新时间:2023-11-04 08:28:08 24 4
gpt4 key购买 nike

<分区>

数据框看起来像这样

col_a
Python PY is a general purpose PY language

Programming PY language in Python PY

Its easier to understand PY

The syntax of the language is clean PY

此代码我已尝试实现此功能但无法获得预期的输出。如果有任何帮助表示赞赏。

下面是我用正则表达式处理的代码:

df['col_a'].str.extract(r"([a-zA-Z'-]+\s+PY)\b")

期望的输出:

col_a                                       col_b_PY     
Python PY is a general purpose language Python PY purpose PY
Programming PY language in Python PY Python PY Programming PY
Its easier to understand PY understand PY
The syntax of the language is clean PY clean PY

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com