【问题标题】:How to load Data Frame or csv file in spacy pipeline nlp?如何在 spacy 管道 nlp 中加载数据框或 csv 文件?
【发布时间】:2017-08-29 05:21:36
【问题描述】:

我正在尝试将数据帧 csv 加载到 spacy 管道中。我收到参数字符串错误,这是我的代码。

from __future__ import unicode_literals
nlp = spacy.load('en')

data = pd.read_csv("sometextdata.csv")
text = []
for line in data.Line:
    text.append(clean_text(line))

    text_spacy = nlp(data['Line'])
    data['Line'].apply(nlp)
    document = nlp(text)
TypeError: Argument 'string' has incorrect type (expected unicode, got str)

我尝试以不同的方式加载我得到了同样的错误。

平台:操作系统 - Mac 和 python 2.7

【问题讨论】:

    标签: python python-2.7 pandas nlp spacy


    【解决方案1】:

    您应该将可变文本转换为 unicode。如您所见,现在具有 str 类型。例如,您可以尝试像这样转换

    document = nlp(unicode(text))
    

    或者喜欢

    document = nlp(text.decode())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      • 1970-01-01
      • 2023-02-22
      • 2017-09-13
      • 2018-05-05
      • 1970-01-01
      • 2017-06-03
      相关资源
      最近更新 更多