Python 对于word,枚举(句子)中的标记:TypeError:';int';对象是不可编辑的
我在做孟加拉语的词性标注 但这个错误表明 当我写print(word+tag)时,没有数据进入标记文件Python 对于word,枚举(句子)中的标记:TypeError:';int';对象是不可编辑的,python,nlp,nltk,Python,Nlp,Nltk,我在做孟加拉语的词性标注 但这个错误表明 当我写print(word+tag)时,没有数据进入标记文件 taggedOutput = doTag(tagger,untagged) tagged = pd.read_csv("Tagged_bangla_hmm.csv",'w',encoding="utf-8", header=None, delimiter = r'\s+',skip_blank_lines=False, engine='python') for senten
taggedOutput = doTag(tagger,untagged)
tagged = pd.read_csv("Tagged_bangla_hmm.csv",'w',encoding="utf-8", header=None, delimiter = r'\s+',skip_blank_lines=False, engine='python')
for sentence in tagged:
for word, tag in enumerate(sentence):
tagged.write( word + tag )
print(tagged)
print('\n\n')
print ('Finished Tagging')
您需要显式关闭该文件才能查看所做的更改。您正在尝试将整数连接到字符串
taged.write(word+tag)
应该是taged.write(str(word)+tag)
我将代码taged.write()更改为taged.to_csv(str(word)+tag),然后这种情况会被标记。to_csv(str(word)+tag TypeError:只能将str(而不是“int”)连接到strI,在代码中的任何地方都看不到taged.to_csv()
。如果你想让我帮你,你必须发布完整的代码。顺便说一下,问题已经解决了。但是没有单词或标记传输到文件我也想关闭文件,但是Dataframe没有名为close tagged的属性。close()AttributeError:'Dataframe'对象没有属性'close',你应该使用本机open()函数:它可以工作。感谢您宝贵的时间和宝贵的回复