title: Python How to pivot this table
body: <p>Hi there I have a table that looks like this:</p>
  <pre><code>df = pd.DataFrame({'CaseNo':[1,1,1,1,2,2,2,2],
                    'PatientID':[101,101,101,101,102,102,102,102],
                    'RequestDate':['2020-02-10','2020-02-10','2020-02-11','2020-02-11',
                                   '2020-02-12','2020-02-12','2020-02-13','2020-02-13'],
                    'CollectionDate':['2020-02-11','2020-02-11','2020-02-12','2020-02-12',
                                      '2020-02-13','2020-02-13','2020-02-14','2020-02-14'],
                    'TestCode':['ALT','AST','CRE','DB','ALT','AST','CRE','DB'],
                    'TestResult':[21, 27, 94, 2, 25, 22, 98, 3],
                    'Units':['U/L','U/L','umol/L','umol/L','U/L','U/L','umol/L','umol/L']})
  </code></pre>
  <p><a href="https://i.stack.imgur.com/w8kBQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w8kBQ.png" alt="enter image description here" /></a></p>
  <p>In python, how can I pivot it to get the following expected output:</p>
  <p><a href="https://i.stack.imgur.com/bBPVd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bBPVd.png" alt="enter image description here" /></a></p>
  <p>This is a little tricky as it seems to be panel data, ie time series + cross sectional data.</p>