title: apply vs nested for loops
body: <p>I'm trying to build a dataframe in python that is filled with 1s and 0s, depending on the number in one column:</p>
  
  <pre><code>Date        Hour
  2005-01-01  1
  2005-01-01  2
  2005-01-01  3
  2005-01-01  4
  </code></pre>
  
  <p>I want to make new columns based on the number in "Hour", and fill each column with a 1 if that row is equal to the value in "Hour", or 0 if not.</p>
  
  <pre><code>Date        Hour HE1 HE2 HE3 HE4
  2005-01-01  1    1   0   0   0
  2005-01-01  2    0   1   0   0
  2005-01-01  3    0   0   1   0
  2005-01-01  4    0   0   0   1
  </code></pre>
  
  <p>I can do it with this code, but it takes a long time:</p>
  
  <pre><code>for x in range(1,5):
      _HE = 'HE' + str(x)
      for i in load.index:
          load.at[i, _HE] = 1 if load.at[i,'Hour']==x else 0
  </code></pre>
  
  <p>I feel like this is a great application (no pun intended) for .apply(), but I can't get it to work right.</p>
  
  <p>How would you speed this up?</p>