我知道这可能相当容易,但是假设我具有带Datetime索引的以下数据框:
DateTimeIndex Val_1 Val_2
1995-01-11 461.66 0.0
1995-01-12 461.64 0.0
1995-01-13 465.97 1.0
1995-01-16 469.38 1.0
1995-01-17 470.05 1.0
1995-01-18 469.72 1.0
1995-01-19 466.95 1.0
我想遍历数据帧并在val_2 == 1的行之后选择下一行,在这种情况下,应该是第4行(1995-01-16 469.38 1.0)
col_name = 'Val_2'
for index, row in df.iterrows():
if row[col_name] == 1:
# select subsequent row
# do sth else