title: How to get the next hour from a datetime column in a Pandas dataframe?
body: <p>I have a Pandas dataframe that looks like this :</p>
  <pre><code> #   date 
  ---  ------------------- 
   0   2022-01-01 08:00:00
   1   2022-01-01 08:01:00
   2   2022-01-01 08:52:00
  </code></pre>
  <p>My goal is to add a new column that contains a datetime object with the value of the next hour. I looked at the documentation of the <a href="https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.ceil.html" rel="nofollow noreferrer">ceil function</a>, and it works pretty well in most cases.</p>
  <h2>Issue</h2>
  <p>The problem concerns hours that are perfectly round (like the one at #0) :</p>
  <pre class="lang-py prettyprint-override"><code>df[&quot;next&quot;] = (df[&quot;date&quot;]).dt.ceil(&quot;H&quot;)
  </code></pre>
  <pre><code> #   date                next
  ---  ------------------- -------------------
   0   2022-01-01 08:00:00 2022-01-01 08:00:00 &lt;--- wrong, expected 09:00:00
   1   2022-01-01 08:01:00 2022-01-01 09:00:00 &lt;--- correct
   2   2022-01-01 08:52:00 2022-01-01 09:00:00 &lt;--- correct
  </code></pre>
  <h2>Sub-optimal solution</h2>
  <p>I have come up with the following workaround, but I find it really clumsy :</p>
  <pre class="lang-py prettyprint-override"><code>def nextHour(current):
    return pd.date_range(start=current, periods=2, freq=&quot;H&quot;)[1]
  
  df[&quot;next&quot;] = (df[&quot;date&quot;]).apply(lambda x: nextHour(x))
  </code></pre>
  <p>I have around 1-2 million rows in my dataset and I find this solution extremely slow compared to the native <code>dt.ceil()</code>. Is there a better way of doing it ?</p>