[英]List Index out of range.. works on google colab but not on local machine?
[英]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.