Home > Net >  How to turn list of arrays into dataframe?
How to turn list of arrays into dataframe?

Time:04-29

I have a list of arrays:

[array([10,20,30]), array([5,6,7])]

How to turn it into pandas dataframe? pd.DataFrame() puts arrays in on column. desired result is:

0     1    2
10    20   30
5     6    7

0 1 2 here are column names

CodePudding user response:

import pandas as pd
import numpy as np
a = [np.array([10,20,30]), np.array([5,6,7])]
print(pd.DataFrame(a))

CodePudding user response:

Make sure you put the np before the array.

import pandas as pd
import numpy as np

list = [np.array([10,20,30]), np.array([5,6,7])]
df = pd.DataFrame(list)
print(df)

output:

    0   1   2
0  10  20  30
1   5   6   7

If you still get an error, is the list of arrays a result from previous data manipulation or did you manually type out the values / array lists?

  • Related