Getting ValueError when creating new dataframe from numpy arrays

Question:

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 ?

Asked By: user3668129

||

Answers:

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]
Answered By: Ynjxsjmh
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.