TypeError:只能连接列表(不是“str”)

2024-05-16 22:05:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做词性标注,算法是Baum-Welch算法。 我想发送.csv文件中的类型和标记,但在运行代码后,会显示此错误

untagged =pd.read_csv('test.csv','UTF-8','r')

print ('Tagging...')

#taggedOutput = doTagging(sent,untagged)

[w for w in sent if w in untagged]

tagged = pd.read_csv("Tagged_bangla_hmm.csv",'a',encoding="utf-8", 

header=None, delimiter = r'\s+',skip_blank_lines=False, engine='python')

for sentence in tagged:

     a = zip('types', 'tags')

     for word, tag in  a:

         tagged.to_csv( types +'/' + tags + ' ')

         print(tagged)

         print('\n\n')

         tagged.close()

         print ('Finished Tagging')

         i=0

Tags: csvin算法forreadtagssenttypes
1条回答
网友
1楼 · 发布于 2024-05-16 22:05:48

首先,写a = zip(types, tags)而不是a = zip('types', 'tags')去掉'types'和“tags”周围的引号。你知道吗


其次,当您编写types +'/' + tags + ' '时,types必须是字符串,tags必须是字符串。加号运算符(+)不能将列表和字符串相加。它只能将列表添加到列表或将字符串添加到字符串。你知道吗

相关问题 更多 >