title: Pandas: extract hour from timedelta
body: <p><a href="https://stackoverflow.com/questions/47795361/how-to-convert-a-column-of-integer-to-standard-hour-time-in-python">This answer</a> explains how to convert integers to hourly timesteps in Pandas. I need to do the opposite.</p>
  
  <p>My dataframe <code>df1</code>:</p>
  
  <pre><code>   A
  0  02:00:00
  1  01:00:00
  2  02:00:00
  3  03:00:00
  </code></pre>
  
  <p>My expected dataframe <code>df1</code>:</p>
  
  <pre><code>   A         B
  0  02:00:00  2
  1  01:00:00  1
  2  02:00:00  2
  3  03:00:00  3
  </code></pre>
  
  <p>What I am trying:</p>
  
  <pre><code>df1['B'] = df1['A'].astype(int)
  </code></pre>
  
  <p>This fails because:
  <code>TypeError: cannot astype a timedelta from [timedelta64[ns]] to [int32]</code></p>
  
  <p>What is the best way to do this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>If I try <code>df['B'] = df['A'].dt.hour</code>, then I get:
  <code>AttributeError: 'TimedeltaProperties' object has no attribute 'hour'</code></p>