I have the following pandas dataframe df:
timestamp col1
2021-01-11 11:00 0
2021-01-11 12:00 0
2021-01-11 13:00 1
2021-01-11 14:00 1
2021-01-11 15:00 0
I need to get a timestamp of the first row when col1 is equal to 1. The expected answer is 2021-01-11 13:00.
This is my current solution:
first = None
for index,row in df.iterrows():
if row["col1"] == 1:
if not first:
first = row["timestamp"]
break
How can I simplify it and make it faster?