python pandas ... alternatives to iterrows in pandas to get next rows value (NEW)
While it's not the most "fancy" way - I would just use a numeric iterator and access lines i and i+1
I have a df in pandas
import pandas as pd
import pandas as pd
df = pd.DataFrame(['AA', 'BB', 'CC'], columns = ['value'])
I want to iterate over rows in df. For each row i want rows value and next rows value.
Here is the desired result.
0 1 AA BB
1 2 BB CC
I have tried a pairwise() function with itertools.
from itertools import tee, izip
def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return izip(a, b)

import pandas as pd
df = pd.DataFrame(['AA', 'BB', 'CC'], columns = ['value'])

for (i1, row1), (i2, row2) in pairwise(df.iterrows()):
    print i1, i2, row1["value"], row2["value"]
But, its too slow. Any idea how to achieve the output with iterrows ? I would like to try pd.apply for a large dataset.