【发布时间】:2021-02-03 12:07:43
【问题描述】:
我有一个地址列如下的数据框。我想拆分此列,以便将国家、城市和机构分成不同的列。具有挑战性的部分是每个细胞都有不同的结构。所有这些单元格的共同点是它们以城市、国家/地区结尾,但在某些情况下,例如行索引 3,有多个条目。
id address
------------------------------------------------------------------------------------------------
0 223 Department of GI and HPB Surgery, University Hospital Northern Norway, Breivika, Tromsø, Norway; Institute of Clinical Medicine, University of Tromsø, Tromsø, Norway
1 223 Department of Surgery, University Hospital Maastricht, Maastricht, The Netherlands; NUTRIM School for Nutrition, Toxicology and Metabolism, Maastricht University, Maastricht, The Netherlands
2 223 Department of Surgery, University Hospital Maastricht, Maastricht, The Netherlands; NUTRIM School for Nutrition, Toxicology and Metabolism, Maastricht University, Maastricht, The Netherlands
3 223 Department of Surgery, Närebro University Hospital, Närebro; Department of Molecular Medicine and Surgery, Karolinska Institutet, Stockholm, Sweden'}, {'id': '9900', 'name': 'Närebro universitet, Institutionen för läkarutbildning
4 223 Clinical Surgery, University of Edinburgh, Royal Infirmary of Edinburgh, Edinburgh, UK
5 223 Division of Gastrointestinal Surgery, Nottingham Digestive Diseases Centre, National Institute for Health Research, Biomedical Research Unit, Nottingham University Hospitals, Queen's Medical Centre, Nottingham, UK
6 223 Hospital of Lausanne (CHUV), Lausanne, Switzerland
7 223 Department of GI and HPB Surgery, University Hospital Northern Norway, Breivika, Tromsø, Norway; Institute of Clinical Medicine, University of Tromsø, Tromsø, Norway
8 223 Clinical Surgery, University of Edinburgh, Royal Infirmary of Edinburgh, Edinburgh, UK
9 223 Department of GI and HPB Surgery, University Hospital Northern Norway, Breivika, Tromsø, Norway; Institute of Clinical Medicine, University of Tromsø, Tromsø, Norway
有人可以帮忙吗?
注意上面的数据框是我的数据框的一个子集,这就是为什么 id 列对于所有行都具有相同的值。原始数据框有大约 10k 行,这就是为什么不能在这里分享。
【问题讨论】:
-
您可以创建一个包含所有国家/地区的列表,另一个包含城市的列表,然后,您可以使用正则表达式来提取正确的字符串。 String 的其余部分将是机构。
-
你的逻辑似乎是合理的。你能提供你的代码sn-p吗?
-
这里可以使用named entity recognition。