【发布时间】:2014-06-02 19:02:42
【问题描述】:
我在 pandas 中有一个 df
import pandas as pd
df = pd.DataFrame(['AA', 'BB', 'CC'], columns = ['value'])
我想遍历 df 中的行。对于每一行我想要 rows value and next rows 值
类似的东西(它不起作用):
for i, row in df.iterrows():
print row['value']
i1, row1 = next(df.iterrows())
print row1['value']
结果我想要
'AA'
'BB'
'BB'
'CC'
'CC'
*Wrong index error here
在这一点上,我有办法解决这个问题
for i in range(0, df.shape[0])
print df.irow(i)['value']
print df.irow(i+1)['value']
有没有更有效的方法来解决这个问题?
【问题讨论】: