How to make dataframe from list of list

Viewed 43

I have searched but till not able to figure out how to make data frame from below:

0       ([179, 142, 176, 177, 176, 180, 180, 180, 180,...
1       ([353, 314, 349, 349, 344, 359, 359, 359, 359,...
2       ([535, 504, 535, 535, 535, 540, 540, 540, 540,...
3       ([711, 664, 703, 703, 703, 721, 721, 721, 721,...
4       ([850, 810, 822, 822, 842, 857, 857, 857, 857,.

below is how single data looks

([179, 142, 176],
 ['Qtr- Oct-20','Qtr- Oct-20','Qtr- Oct-20',],
 ['High','Low','Close'],
 [43.8, 26.05,33.1])

what i want is

      0  1           2               3
0   179 Qtr- Oct-20 High            43.8
1   142 Qtr- Oct-20 Low             26.05
2   176 Qtr- Oct-20 High_Volume     1123132
3   177 Qtr- Oct-20 High_Delivery   42499

what i am getting

      0
0   ([179, 142, 176, 177, 176, 180, 180, 180, 180,...
1   ([353, 314, 349, 349, 344, 359, 359, 359, 359,...
2   ([535, 504, 535, 535, 535, 540, 540, 540, 540,...
1 Answers

Let's do apply + pd.Series.explode:

pd.DataFrame(df['col'].tolist()).apply(pd.Series.explode).reset_index(drop=True)

     0            1      2      3
0  179  Qtr- Oct-20   High   43.8
1  142  Qtr- Oct-20    Low  26.05
2  176  Qtr- Oct-20  Close   33.1

Note: df['col'] is the column in the dataframe which contains list of lists.

Related