Reputation:
list = [[1,1,56],
[20,2,78],
[30,3,34],
[40,4,98]]
this is my list of list and i want to make a dataframe like this-;
a b c
1 1 56
20 2 78
30 3 34
40 4 98
i did a code
df = pd.DataFrame(list)
df = df.transpose()
df.columns = ["a", "b", "c"]
it gives me a error like Length mismatch: Expected axis has 4 elements, new values have 3 elements
please help me thanks in advance
Upvotes: 2
Views: 5699
Reputation: 863501
First dont use list
because reserved code word in python and then only pass columns parameter, transpose
is not necessary:
L = [[1,1,56],
[20,2,78],
[30,3,34],
[40,4,98]]
df = pd.DataFrame(L, columns=["a", "b", "c"])
print (df)
a b c
0 1 1 56
1 20 2 78
2 30 3 34
3 40 4 98
Upvotes: 3