I am trying to create a DataFrame like this:
column_names= ["a", "b", "c"]
vals = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
df = pd.DataFrame(vals, columns=column_names)
Which results in the following DataFrame:
a b c
0 1 2 3
1 4 5 6
2 7 8 9
I suppose this is the expected result. However, I am trying to achieve this result:
a b c
0 1 4 7
1 2 5 8
2 3 6 9
Where each nested list in vals
corresponds to a whole column instead of a row.
Is there a way to get the above DataFrame without changing the way the data is passed to the constructor? Or even a method I can call to transpose the DataFrame?