Make a dataframe from list of variables which are lists

I have a list of variables in which each variable is a list. And I want to use that list to form a dataframe.

A=[1,2]
B=[4,3]
C=[A,B]

I want to create the dataframe using the list C that looks like this:

A B
1 4
2 3

I tried doing it like this

headers=['A','B']
df = pd.DataFrame(C, columns=headers)

But it doesn’t work. Any suggestions on how to achieve it?

>Solution :

headers=['A','B']
df = pd.DataFrame(columns=headers)

for i in range(len(headers)):
    df[headers[i]] = pd.Series(C[i])
#output
   A  B
0  1  4
1  2  3

Leave a Reply