Home > database >  Convert to DataFrame?
Convert to DataFrame?

Time:10-18

How can I convert 20137 numpy values (rows) into a DataFrame

Shape of numpy data (20137, 1, 6912)

I am using this code to convert

data = pd.DataFrame(data)

It gives me this error

 Must pass 2-d input. shape=(20137, 1, 6912)

CodePudding user response:

The error says it all. OP is passing a 3 dimensional data and one must pass a 2-d input.

Depending on the desired output one thing one can do is the following

df = pd.DataFrame(data.reshape(20137, 6912))

CodePudding user response:

For improve performance avoid reshape, simplier is selecting by data[:,0,:]:

data = np.arange(6).reshape(2,1,3)
print (data)
[[[0 1 2]]

 [[3 4 5]]]

print (data.shape)
(2, 1, 3)

data = pd.DataFrame(data[:,0,:])
print (data)
   0  1  2
0  0  1  2
1  3  4  5
  • Related