I have 3 numpy
arrays with the following shapes:
a.shape = (120,)
b.shape = (120,)
c.shape = (120,)
I'm trying to create dataframe with the following way:
df = pd.DataFrame(data = [a, b, c], columns = ["a", "b", "c"])
and I'm getting the following error:
ValueError: 3 columns passed, passed data had 120 columns.
How can I create this dataframe with the 3 columns ?
CodePudding user response:
Let's try
df = pd.DataFrame(data = [a, b, c], index = ["a", "b", "c"]).T
# or
df = pd.DataFrame(data = {'a': a, 'b': b, 'c': c})
print(df)
a b c
0 0 0 0
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
.. ... ... ...
115 115 115 115
116 116 116 116
117 117 117 117
118 118 118 118
119 119 119 119
[120 rows x 3 columns]