简体   繁体   中英

Python Exception: Data must be 1-dimensional pandas trying to get two columns

I am trying to create 2 columns but I am getting an error. I don't know what I am doing wrong. I searched a lot but couldn't find a solution.

Error: *raise Exception("Data must be 1-dimensional")

Exception: Data must be 1-dimensional*

Questions = ['Q1', 'Q2', 'Q3','Q4','Q5', 'Q6', 'Q7', 'Q8', 'Q9', 'Q10']
#model_1 = RBM(nv,nh) ## ERROR!!!

Weight = rbm.W.detach().numpy()
df = pd.DataFrame({'Questions': Questions,
                   'Weights': Weight
                   }

The pd.DataFrame line looks fine, so it seems that the issue is probably that Weight has more than one dimension. You can check the dimensions of Weight with Weight.shape. If it is two dimensional with 1 as the second dimension (for example (10,1)), you can reshape it with

Weight = Weight.reshape(Weight.shape[0],)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM