0

I have a DataFrame:

import pandas as pd
data = [[1,11,2],[2,11,3],[1,22,7],[2,22,8],[3,22,9],[1,33,15],[2,33,16],[3,33,17],[4,33,18],[5,33,19]]
df = pd.DataFrame(data,columns=['Date','Leg','Amt'])
print(df)
OUT:
       Date  Leg  Amt
    0     1   11    2
    1     2   11    3
    2     1   22    7
    3     2   22    8
    4     3   22    9
    5     1   33   15
    6     2   33   16
    7     3   33   17
    8     4   33   18
    9     5   33   19

I would like to convert it to the format:

Date   11  22  33
1      2   7   15
2      3   8   16
3      X   9   17
4      X   X   18
5      X   X   19

X = Don't care could be NA/Nan

I want to do some analysis datewise for each Leg, so trying to bring the Legs data date wise.

Many thanks, ahead!

007
  • 23
  • 6

0 Answers0