Pandas iterate over DataFrame row pairs

前端 未结 4 2022
执笔经年
执笔经年 2020-12-10 21:35

How can I iterate over pairs of rows of a Pandas DataFrame?

For example:

content = [(1,2,[1,3]),(3,4,[2,4]),(5,6,[6,9]),(7,8,[9,10])]
df = pd.DataFra         


        
4条回答
  •  半阙折子戏
    2020-12-10 21:48

    To get the output you've shown use:

    for row in df.index[:-1]:
        print 'row 1:'
        print df.iloc[row].squeeze()
        print 'row 2:'
        print df.iloc[row+1].squeeze()
        print
    

提交回复
热议问题