繁体   English   中英

在列表上的元组上使用 function 在 Google Colab 中有效,但在本地计算机上无效

[英]Using function on tuples on list works in Google Colab, but not on local machine

我不知道发生了什么事。 在我的 google colab 环境中,我有一个 dataframe,它使用 spaCy 对来自 NYT 的片段的命名实体提取如下所示:

raw_data = {'id': [1,2,3],
        'ents': [[(('PARIS', 'GPE'), 6), (('French', 'NORP'), 3), (('France', 
         'GPE'), 1)],
           [(('CHINA','GPE'), 3), (('British', 'NORP'), 2), (('Hong Kong', 
           'GPE'), 1)],
       [(('Chile','GPE'), 3), (('spanish', 'NORP'), 1), (('Hong Kong', 'GPE'), 
       1)]]}

df = pd.DataFrame(raw_data)

我应用 function 只取回实体超过计数阈值的实体,

def limit_ents(ents):
    for i in ents:
        if i[1] >=2:
            return [i[0][0] for i in ents]

df['limit_ents'] = df['ents'].apply(limit_ents)

这一切在 Google Colab 中运行良好,但是当我在本地机器上执行此操作时,我得到 IndexError: string index out of rangeing pointing to the line in the function "if ent[1] >=2:

这是 Linux 与 Windows 上正在运行的 pandas 吗? 我在这两个地方都运行 pandas 1.1.3。 我在做一些非常愚蠢的事情吗?

提前感谢大家的帮助。

多哈,在我的头撞到墙上之后。 事实证明,我需要做的就是检查 object 是否有类型列表。 我正在阅读 *.csv 提取的实体,并且该列的值不再是类型列表 - 当我执行 isinstance 时评估为 False。 应该将我原来的 output 保存为泡菜。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM