typeerror:预期的字符串或字节类对象我收到此错误

5kgi1eie  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(317)

这是我遇到错误的代码。我有一个excel表格,其中两列a包含乌尔都语文本,b列包含文本类true或false

  1. counter = collections.Counter()
  2. maxlen = 0
  3. c=0
  4. df=pd.read_excel(INPUT_FILE)
  5. df.columns=['Text','label']
  6. label=df['label']
  7. sent=df['Text']
  8. # print (sent)
  9. content=df
  10. for index, row in df.iterrows():
  11. # print(row['Text'], row['label'])
  12. words = [x.lower() for x in nltk.word_tokenize(row['Text'])] # here i am getting error
  13. if len(words) > maxlen:
  14. maxlen = len(words)
  15. c=c+1
  16. for word in words:
  17. counter[word] += 1
  18. print (len(counter))
  19. print (maxlen)

我已经尝试过不同的解决方案,但都是徒劳的。请根据我的代码和我的问题向我推荐一些代码或解决方案。我在用乌尔都语,也许这是个问题。

weylhg0b

weylhg0b1#

"word_tokenize" 需要 "string" 键入作为输入,您将传递一个看起来不同的对象 type .
请参阅:
https://www.nltk.org/api/nltk.tokenize.html

  1. word_tokenize(s)[source
  2. Tokenize a string to split off punctuation other than periods

相关问题