擅长:python、mysql、java
<p>试试这个:</p>
<p>版本1</p>
<pre><code>NaT = pd.NaT
df['Rolling2'] = np.where(df['starttime'].shift(-1) > df['endtime'], NaT,'drop')
df['Rolling2'] = df['Rolling2'].shift(1)
df['RollingStart'] = np.where(df['Rolling2'] =='drop',None,df['starttime'])
df['RollingStart'] = pd.to_datetime(df['RollingStart']).ffill()
df['RollingEnd'] = df['endtime']
del df['Rolling2']
</code></pre>
<p>版本2。在</p>
^{pr2}$