首页 > 解决方案 > 从's'中的'data'变量中获取什么数据?

问题描述

我正在尝试理解 NER,我看到以下代码行,我无法弄清楚这一行的含义,

s = self.data[self.data["Sentence #"] == "Sentence: {}".format(self.n_sent)]

我正在阅读来自 https://www.depends-on-the-definition.com/introduction-named-entity-recognition-python/的代码

标签: python

解决方案


为了n_sent=1

"Sentence: {}".format(self.n_sent)

将生成字符串Sentence: 1并将其与第一列匹配使用

self.data["Sentence #"] == "Sentence: {}".format(self.n_sent)

最后在条件匹配的地方使用布尔掩码对数据帧进行切片以获取特定句子的数据

s = self.data[self.data["Sentence #"] == "Sentence: {}".format(self.n_sent)]

并进一步n_sent+=1增加将重复该过程以获得下一个句子


推荐阅读