Every time I try to create a nested list using list comprehension it ends up being a major headache or comes out incorrectly. I have a transposed data frame of four variables that I'm working with that has 9 columns of each variable. For example:
Date0, Date1, Date2, Date3 ... Date 9
GMV0, GMV1, GMV2, GMV3 .... GMV9
Revenue0, Revenue1, Revenue2, Revenue3 .... Revenue9
I am trying to create a nested list for each of these columns. The desired list is as follows:
[[Date0, GMV0, Revenue0], [Date1, GMV1, Revenue1], [Date2, GMV2, Revenue2] ... [Date9, GMV9, Revenue9]]
I can currently create the desired list using
date=[col for col in test.columns if 'Date' in col]
gmv=[col for col in test.columns if 'GMV' in col]
rev=[col for col in test.columns if 'Gross Revenue' in col]
vars=[[Date[i], gmv[i], rev[i]] for i in range(len(Date))]
But this is quite inefficient and I'm quite positive this is a one-liner code.
Can someone help with the correct list comprehension (or possibly some other method that is specific to transposed data) and help me wrap my head around it?