我有一個每行重複3次的數據幀。在循環的過程中,如何確定是否以前看過一行,然後執行某些操作,即在循環的第二次出現處打印某些內容?在循環數據幀時計算行的發生次數
print df
user date
0 User001 2014-11-01
40 User001 2014-11-01
80 User001 2014-11-01
120 User001 2014-11-08
200 User001 2014-11-08
160 User001 2014-11-08
280 User001 2014-11-15
240 User001 2014-11-15
320 User001 2014-11-15
400 User001 2014-11-22
440 User001 2014-11-22
360 User001 2014-11-22
... ...... ..........
... ...... ..........
1300 User008 2014-11-22
1341 User008 2014-11-22
1360 User008 2014-11-22
for line in df.itertuples():
user = line[1]
date = line[2]
print user, date
#do something after second occurrence of tuple i.e. print "second occurrence"
('User001', '2014-11-01')
('User001', '2014-11-01')
second occurrence
('User001', '2014-11-01')
('User001', '2014-11-08')
('User001', '2014-11-08')
second occurrence
('User001', '2014-11-08')
('User001', '2014-11-15')
('User001', '2014-11-15')
second occurrence
('User001', '2014-11-15')
('User001', '2014-11-22')
('User001', '2014-11-22')
second occurrence
('User001', '2014-11-22')
('User008', '2014-11-22')
('User008', '2014-11-22')
second occurrence
('User008', '2014-11-22')