I am facing the following dataframe.
| Date | Security | Field | Value | |
|---|---|---|---|---|
| 0 | 2022-05-03 08:00:12.394000 | CFI2Z2 | VALUE | 83.3 | 
| 1 | 2022-05-03 08:00:12.394000 | CFI2Z2 | VOLUME | 1 | 
| 2 | 2022-05-03 08:00:12.460000 | TRNLTTFFVMc1 | VALUE | 83.4 | 
| 3 | 2022-05-03 08:00:12.460000 | TRNLTTFFVMc1 | VOLUME | 1 | 
| 4 | 2022-05-03 08:00:12.460000 | TRNLTTFFVMc1 | VALUE | 83.23 | 
| 3 | 2022-05-03 08:00:12.460000 | TRNLTTFFVMc1 | VOLUME | 2 | 
Note that the column "Date" is not unique. Neither globally or and not per group.
I am trying to achieve the following transformation.
| ('TRNLTTFFVMc1', 'VALUE') | ('TRNLTTFFVMc1', 'VOLUME') | ('CFI2Z2', 'VALUE') | ('CFI2Z2', 'VOLUME') | |
|---|---|---|---|---|
| 2022-05-03 08:00:12.394000 | nan | nan | 83.3 | 1 | 
| 2022-05-03 08:00:12.460000 | 83,27 | 3 | nan | nan | 
Note that the output columns index is a MultiIndex.
MultiIndex([('TRNLTTFFVMc1',  'VALUE'),
            ('TRNLTTFFVMc1', 'VOLUME'),
            (      'CFI2Z2',  'VALUE'),
            (      'CFI2Z2', 'VOLUME')],
           )
For groups with multiple VOLUME/PRICE pairs I would like to calculate the Volume-Weighted Average Price.
The problem is that I can't just pivot, because the date is not unique. I am not sure how to proceed.
 
     
    