我的数据框看起来像这样:
#INPUT #DATE #NAME #VALUE
TEST1 20160620 AACT 203478480
TEST2 20160621 AACT 203478480
我想将它分组,并让它由NAME分开,我还需要在那里添加日期以附加VALUE中的更改记录:
#NAME DATE VALUE
AACT 20160602 186615450
20160603 186615450
20160604 186615450
20160605 190045153
20160606 186615450
20160607 186615450
20160608 160451251
20160609 186615450
201606010 186615450
BAML 20160602 21900000
20160603 21900000
20160604 21900000
20160605 21900000
20160606 21900000
20160607 21900000
20160608 21900000
20160609 12096251
201606010 21900000
201606011 21900000
201606012 21900000
201606013 21900000
201606014 21900000
基本上我需要对每个组进行差异分析,在VALUE上方使用VALUE。我已经尝试了以下内容:
group3 = frame['VALUE'].groupby(frame['NAME'], sort = True)
for name, group in group3:
for diff in [elem for elem in group.diff() if elem > 0]:
print (name, diff)
但是,这并没有给我该记录的日期,它只给我NAME和值的差异。
我希望我的输出是这样的:
('AACT', 20160605, 190045153)
('AACT', 20160608, 160451251)
('BAML', 20160609, 12096251)
感谢您的帮助