擅长:python、mysql、java
<p>可能有一种更简单的方法来实现这一点,但我相信,考虑到您的条件,这是可行的:</p>
<pre><code># reset index to make our life easier
df = df.reset_index()
# get rows with small timediffs
small_timediffs = df.loc[df.Timediff <= 0.1]
# get rows immediately above rows with small timediffs
prev_small_timediffs = df.loc[small_timediffs.index-1]
# helper function to allow comparison of timestamps without milisseconds
remove_milisseconds = lambda x: x.split('.')[0]
# compare if timestamps from rows with small timediffs
# and rows above them are the same
stamps = small_timediffs.timestamp.apply(remove_milisseconds).values
prev_stamps = prev_small_timediffs.timestamp.apply(remove_milisseconds).values
cond = (stamps == prev_stamps)
# extract results based on both conditions
# (small timediff and same timestamp)
result = df.loc[~df.index.isin(small_timediffs.loc[cond].index-1)]
</code></pre>