Python - Iterrow through pandas dataframe and assign and conditionally update datetime variable
<p>I'm a Python novice and was wondering if anyone could help me.</p>

<p>I want to iterate through datetime column in a pandas data frame, while for each iteration update a variable with the most recent time. Let's assume this is my data:</p>

<pre><code>    Time
06:12:50
06:13:51
06:13:51
06:13:50
06:14:51
06:14:49
</code></pre>

<p>For my result, I want it to look something like this:</p>

<pre><code>RecentTime:
   06:12:50
   06:13:51
   06:13:51
   06:13:51
   06:14:51
   06:14:51
</code></pre>

<p>I think the code should look something like this, but I have had trouble with it and can't figure out why. This is my code:</p>

<pre><code>RecentTime = [] # Store list of most recent time for each row
Index: None       # Create empty variable
# Loop through 
for index, row in data.iterrows():
    index = row['Time']   # Save value as index
    if index &gt;= row['Time']: # If time is greater than current row
    index = row['Time']
        RecentTime.append(index) # Append most recent variable into list
    else:
        continue
</code></pre>

<p>For some reason, this is my result:</p>

<pre><code>RecentTime
  06:12:50
  06:13:51
  06:13:51
  06:13:50
  06:14:51
  06:14:49
</code></pre>