codebasics / py

Repository to store sample python programs for python learning
6.85k stars 16.77k forks source link

Issue converting 3-dimensional dataframe to 3-dimensional array #22

Open danushaaditya opened 4 years ago

danushaaditya commented 4 years ago

I first created an array: (3 dimensional array)

nlist= [[[1,2,3],[4,5,6],[7,8,9]],[[10,11,12], [13,14,15], [16,17,18]],[[19,20,21],[22,23,24],[25,26,27]]]
import numpy as np
narray = np.array(nlist)

Then I converted it into a dataframe using: (3 dimensional DataFrame)

import pandas as pd
df = pd.DataFrame.from_records(narray)

So I basically converted a 3-dimensional array to a 3-dimensional dataframe. Now when I try to get it back as an array using: new_list = np.array(df)

Now this returns a 2-dimensional array. But I want the original 3-dimensional array. What do I do?

suhas004 commented 4 years ago

It will return your original 3 dimensional array(3,3) . Just Check one more time .