Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting ValueError when creating new dataframe from numpy arrays

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ValueError: 3 columns passed, passed data had 120 columns.

How can I create this dataframe with the 3 columns ?

>Solution :

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]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading