熊猫正则表达式提取两个不同符号前后的所有内容

问题描述

我有一个如下所示的数据框

df = pd.DataFrame({'person_id': [11,11,11],'text':['DOSE: 667 mg - TDS with food - Inject  hypo > 4 test value here','DOSE: 667 mg - TDS with food - Tube','DOSE: 667 mg - TDS with food - PO'],'Summary':['Test','Test1','Test2']})

从上面的数据框中,我想提取所有

a)在DOSE:之后和第一个连字符-

之前

b)再次提取第二连字符-之后的所有内容。

我正在尝试类似以下的内容

df['text'].str.extract('(\d+[A-Za-ZS]*(\-))',expand=True)  # doesn't work 
s1 = df['text'].str.split() # I tried using `str.split`
s1[0][1]  # it goes on like for loop which is not elegant.

以上内容对我有帮助吗?

我希望我的输出如下所示

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)