title: Spreading values into columns (pivot) sensor events in a pandas dataframe
body: <p>I'm fightig with pivoting some sensor data in padas.</p>
  
  <p>I would like to come from this</p>
  
  <pre><code>source_df = pd.DataFrame({'time': [1,1,1,1,2,2,2,2],
                            'sensor_id': ['s1', 's1', 's2', 's2', 's1', 's1', 's2', 's2'],
                            'value_type': ['a', 'b', 'a', 'b','a', 'b','a', 'b',],
                            'value': [1,2,3,4,5,6,7,8]})
  </code></pre>
  
  <p><code>
     time sensor_id value_type  value
  0     1        s1          a      1
  1     1        s1          b      2
  2     1        s2          a      3
  3     1        s2          b      4
  4     2        s1          a      5
  5     2        s1          b      6
  6     2        s2          a      7
  7     2        s2          b      8
  </code></p>
  
  <p>to this form</p>
  
  <pre><code>target_df = pd.DataFrame({'sensor_id': ['s1', 's2', 's1', 's2'],
                            'a': [1, 3, 5, 7],
                            'b': [2, 4, 6, 8],
                            'time': [1, 1, 2, 2]})
  target_df
  </code></pre>
  
  <p><code>
    sensor_id  a  b  time
  0        s1  1  2     1
  1        s2  3  4     1
  2        s1  5  6     2
  3        s2  7  8     2
  </code></p>
  
  <p>Somehow I expect <code>pivot</code> to work... by simply:
  <code>source_df.pivot(columns = 'value_type', values = 'value')</code> - but it does not create the desired outcome.</p>
  
  <p>In <code>R</code> it simply works by </p>
  
  <p><a href="https://i.stack.imgur.com/3bb2E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3bb2E.png" alt="enter image description here"></a></p>
  
  <p>but I really don't understand how to get the same result in <code>pandas</code>.</p>