python - 熊猫在一列字符串中找到确切的单词和之前的单词(多个)并将其附加到python中的新列
问题描述
数据框看起来像这样
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
解决方案
推荐阅读
- django - django.db.utils.IntegrityError: could not create unique index - DETAIL: Key (player)=(Lonergan) is duplicated。- 模型中没有唯一约束
- android - 电子邮件意图值未设置为“TO”:地址
- batch-file - cd 进入与 dir 一起使用的找到文件的目录
- python - 如何解决来自 Xpath 的此错误?
- python-3.x - 将数据框合并为一列中的 None 时省略重复项
- java - WebSocket STOMP 已经覆盖类主体方法 getname() convertAndSendToUser 不起作用
- java - 如果 Firebase 中的另一个子值匹配,如何获取子值?
- mongodb - 在 PSA 设置中的 oplog 中查找数据修改条目
- spring-boot - JSON解析错误:无法构造无字符串参数构造函数/工厂方法的实例以从字符串值(“名称”)反序列化
- ansible - ansible authorized_key 模块覆盖原始文件