Python 使用itertuples()在数据帧中循环并读取下一行

Python 使用itertuples()在数据帧中循环并读取下一行,python,pandas,Python,Pandas,假设我有一个如下所示的数据帧。我可以将输出打印为 2 4 6 import pandas as pd data = [[1,2,'a'],[3,4,'b'],[5,6,'c']] columns = ['a','b','c'] df = pd.DataFrame(data ,columns = ['a','b','c']) for i in df.itertuples(): print(i.b) 现在想象一下,我需要始终打印起始行的下一行值。我如何才能做到这一点。 基本上我只需

假设我有一个如下所示的数据帧。我可以将输出打印为

2
4
6

import pandas as pd

data = [[1,2,'a'],[3,4,'b'],[5,6,'c']]
columns = ['a','b','c']

df = pd.DataFrame(data ,columns = ['a','b','c'])

for i in df.itertuples():
    print(i.b)
现在想象一下,我需要始终打印起始行的下一行值。我如何才能做到这一点。 基本上我只需要输出

4
6
我该怎么做呢

我的方法如下:

for i in df.itertuples():
   # here there should be a if function asking not to go for the last row (first row from upside down of the dataframe) 
     print((i+1).b)

你查过了吗?只需索引数据帧
df.loc[1:,'b']
这种方法不符合我的要求,基本上我需要遍历每一行,然后从下一行开始读取。在这样做之前,您可能需要阅读。除非必要,否则迭代数据帧的行不是一个好主意。这就是索引方法存在的原因。我可能需要更改我刚刚编写的整个程序。将检查它的运行情况。谢谢,伙计