I currently have a Pandas dataframe, df like this
df = pd.DataFrame({'Name': ['A','B','C'], 'Type': ['Car', 'Car', 'Truck'] , '01/01/1991, RED': [10, 26, 30], '01/02/1991, YELLOW': [11,15,5], '01/05/1991, BLUE':[5,8,20]})
Name | Type | 01/01/1991, RED | 01/02/1991, YELLOW | 01/05/1991, BLUE |
A | Car | 10 | 11 | 5 |
B | Car | 26 | 15 | 8 |
C | Truck | 30 | 5 | 20 |
I am looking for the output of
Name | Date | Type | Color | Number
A | 01/01/1991 | Car | RED | 10
A | 01/02/1991 | Car | YELLOW | 11
A | 01/05/1991 | Car | BLUE | 5
B | 01/01/1991 | Car | RED | 26
B | 01/02/1991 | Car | YELLOW | 15
B | 01/05/1991 | Car | BLUE | 8
C | 01/01/1991 | Truck | RED | 30
C | 01/02/1991 | Truck | YELLOW | 5
C | 01/05/1991 | Truck | BLUE | 20
So far, I am able to transpose the table and clean the dates. But am not sure how to go about duplicating the dates in the following manner and set the colors. Would .pivot_table or .transpose() be better for this case? Any insights are appreciated.