我有一个如下所示的数据框
df = pd.DataFrame({'person_id': [11,11,11,11,11,11,11,11,11,11],
'text':['inJECTable 1234 Eprex DOSE 4000 units on NONd',
'department 6789 DOSE 8000 units on DIALYSIS days - IV Interm',
'inJECTable 4321 Eprex DOSE - 3 times/wk on NONdialysis day',
'insulin MixTARD 30/70 - inJECTable 46 units',
'insulin ISOPHANE -- InsulaTARD Vial - inJECTable 56 units SC SubCutaneous',
'1-alfacalcidol DOSE 1 mcg - 3 times a week - IV Intermittent',
'jevity liquid - FEEDS PO Jevity - 237 mL - 1 times per day',
'1-alfacalcidol DOSE 1 mcg - 3 times per week - IV Intermittent',
'1-supported DOSE 1 mcg - 1 time/day - IV Intermittent',
'1-testpackage DOSE 1 mcg - 1 time a day - IV Intermittent']})
我想删除遵循46 units
、3 times a week
、3 times per week
、1 time/day
等模式的单词/字符串
我读的是关于积极和消极的前瞻性和前瞻性
所以,我尝试了下面的方法
[^([0-9\s]*(?=units))] #to remove terms like `46 units` from the string
[^[0-9\s]*(?=times)(times a day)] # don't know how to make this work for all time variants
时间变量如:3 times a day
、3 time/wk
、3 times per day
、3 times a month
、3 times/month
等
基本上,我希望我的输出如下(删除诸如xx个单位、每天xx次、每周xx次、每天xx次、每周xx次、每周xx次、每周xx次等术语)
见regex demo
注意:
\d+
与一个或多个数字匹配。如果您需要匹配任何数字,请考虑使用您期望的格式的其他模式,例如参见{a2}。图案细节
\s*
-零个或多个空格字符\d+
-一个或多个数字\s*
-零个或多个空格(?:units?|times?(?:\s+(?:a|per)\s+|\s*/\s*)(?:d(?:ay)?|w(?:ee)?k|month|y(?:ea)?r?))
-非捕获组匹配:units?
-unit
或units
|
-或times?
-time
或times
(?:\s+(?:a|per)\s+|\s*/\s*)
-a
或per
用1+空格括起来,或/
用0+空格括起来(?:d(?:ay)?|w(?:ee)?k|month|y(?:ea)?r?)
-{如果只需要匹配整个单词,请使用单词边界,
\b
:在熊猫中,使用
相关问题 更多 >
编程相关推荐