我在Python中的新手。我想知道如何標記來自文件的twitter數據。Python:如何從文件標記化?
我的代碼是:
with codecs.open('example.csv', 'r',"utf-8") as f:
for line in f:
tweet = f.readlines()
tokens = word_tokenize(tweet["text"])
print(tokens)
但是錯誤:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-98b6d77c2fcf> in <module>()
2 for line in f:
3 tweet = f.readlines()
----> 4 tokens = word_tokenize(tweet["text"])
5 print(tokens)
TypeError: list indices must be integers or slices, not str
如何提高我的代碼?
是什麼'word_tokenize'?而且'tweet'是'list',訪問列表項,你應該與指數引用它們(如錯誤說) – Arman
我認爲nltk.word_tokenize? – coffeemakr
從代碼word_tokenize:從pythainlp.tokenize導入word_tokenize,我想從example.csv收集文本到鳴叫 –