【发布时间】:2017-06-27 16:37:49
【问题描述】:
我有一个数据框data(带有冗长且不一致的文本字符串注释)和匹配的 ID。我的目标是使用子字符串的list 提取感兴趣的相关子字符串,并为提取的子字符串创建一个新列。有人告诉我,正则表达式是一个很好的起点,但我还没有想出一个可以产生匹配结果的好模式。我希望有人看到这个并指导我以正确的方式解决这个问题。
list = ['sentara williamsburg regional medical',
'shady grove adventist hospital',
'sibley memorial hospital',
'southern maryland hospital center',
'st. mary`s hospital',
'suburban hospital healthcare system',
'the cancer center at lake manassas',
'ucla medical center',
'united medical center- greater southeast community',
'univ of md charles regional medical ctr',
'university of maryland medical center',
'university of north carolina hospital',
'university of virginia health system',
'unknown facility',
'va medical center',
'virginia hospital center-arlington',
'walter reed army medical center',
'washington adventist hospital',
'washington hospital center',
'wellstar health system, inc',
'winchester medical center']
data:
ID Notes
530.0 Cancer is best diag @Wwashington Adventist Hospital
651.0 nan
692.0 GMC-009 can be accessed at ST. Mary`s but not in UCLA Med. Center
993.0 I'm not sure of Sibley; however, Shady Grove Adventist Hosp. is great hospital
044.0 nan
055.0 2015-01-20 was the day she visited WR Army Medical Center in WDC
476.0 nan
预期输出 - 大小写无关紧要!
data_out:
ID Notes
530.0 Washington Adventist Hospital
651.0 nan
692.0 ST. Mary`s Hospital, UCLA Medical Center
993.0 Sibley Memorial Hoapital, Shady Grove Adventist Hospital
044.0 nan
055.0 Walter Reed Army Medical Center
476.0 nan
【问题讨论】:
-
预期输出是什么?
-
刚刚用预期的输出更新了问题
标签: python regex string pandas dataframe