为什么我的代码不能通过前两行

2024-05-23 19:01:28 发布

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

我试图从未加权的二部图中删除自循环,但是我的代码只打印前2行(作为单行),循环的每次迭代都打印这2行(作为单行)。我对熊猫很陌生,可能会犯一些循环错误。你知道吗

我试过只迭代索引,只迭代行,但最终结果是一样的。你知道吗

代码

for index,row in dataset.iterrows():
    x = next(dataset.iterrows())
    y=x[1].to_string().split()
    if ((y[0])!=(y[1])):
        outfile.write(x[1].to_string() + "\n")

输入

% bip unweighted

1 1

1 2

1 3

1 4
...

实际值:

% bip unweighted    1 1

% bip unweighted    1 1 

% bip unweighted    1 1 

...

预期的

% bip unweighted

1 2

1 3

1 4

...

Tags: to代码inforstringindex错误dataset