在Python中,根据相同的下一个单元格连接单元格

2024-09-27 00:16:38 发布

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

enter image description here

我想连接相同treeid列的大小写标记单元格。 我想要的输出应该是

(ne),0
(ko,se),1
(se,ko,ne),2
(ko,ko),3
(se,ko,ne),4

为此,我编写了以下代码:

f = open('dummy.csv','r')
hstring=f.read()
print(hstring)

for i in range(0,len(hstring)):
    temp=hstring[i[3]]
    for j in range(i+1,i+5):
        temp1=hstring[j[3]]
        if temp==temp1:
            print(i[1]+","+j[1])

但是,此代码给出了以下错误:

_io.TextIOWrapper' object is not subscriptable

Tags: 代码in标记forrangeopentempko

热门问题