'python how to make a list into columns in pandas df

I have a list as follows:

[[100,200,300],[10,20,30,40]]

I want to transform each element into a column of a pandas df

The end result looks like:

Col1   Col2    Col3    Col4
100    200     300
10     20      30       40

How can I achieve this? There is a max size of 4 items per list but could be lower.



Solution 1:[1]

lst = [[100,200,300],[10,20,30,40]]
pd.DataFrame(lst).add_prefix("Col")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1