<分区> 分区>
数据框看起来像这样
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
