>>> df = pandas.Dataframe(numpy.random.randint(1,3, (10,5)), columns=['a','b','c','d','e'])>>> df a b c d e0 2 1 2 1 11 2 1 1 1 12 1 2 2 1 23 1 2 1 1 24 2 2 1 1 25 2 2 2 2 16 2 2 1 1 17 2 2 2 1 18 2 2 2 2 19 2 2 2 2 1for k, v in df.groupby('a'): print k print 'normal' print v print 'shifted' print v.shift(1)1normal a b c d e2 1 2 2 1 23 1 2 1 1 2shifted a b c d e2 NaN NaN NaN NaN NaN3 1 2 2 1 22normal a b c d e0 2 1 2 1 11 2 1 1 1 14 2 2 1 1 25 2 2 2 2 16 2 2 1 1 17 2 2 2 1 18 2 2 2 2 19 2 2 2 2 1shifted a b c d e0 NaN NaN NaN NaN NaN1 2 1 2 1 14 2 1 1 1 15 2 2 1 1 26 2 2 2 2 17 2 2 1 1 18 2 2 2 1 19 2 2 2 2 1
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)