我有一个DF,它具有NER分类器的结果,例如:
df =
s token pred tokenID
17 hakawati B-Loc 3
17 theatre L-Loc 3
17 jerusalem U-Loc 7
56 university B-Org 5
56 of I-Org 5
56 texas I-Org 5
56 here L-Org 6
...
5402 dwight B-Peop 1
5402 d. I-Peop 1
5402 eisenhower L-Peop 1
此数据帧中还有许多其他列不相关。现在我想根据它们的sentenceID(=s)和它们的预测标记对标记进行分组,以将它们组合成一个实体:
df2 =
s token pred
17 hakawati theatre Location
17 jerusalem Location
56 university of texas here Organisation
...
5402 dwight d. eisenhower People
通常我会这样做,通过简单地使用像
data_map = df.groupby(["s"],as_index=False, sort=False).agg(" ".join)
并使用重命名函数。然而,由于数据包含不同类型的字符串(B,I,L-Loc/Org..),我不知道如何准确地执行它
任何想法都很感激
有什么想法吗
您可以同时按
s
和tokenID
分组,并按如下方式聚合:一个解决方案通过一个辅助列
请注意,这与所需的输出不完全匹配;似乎涉及到一些特定于数据的处理方法
相关问题 更多 >
编程相关推荐