Home > Enterprise >  Error in labelling the name of the columns using pandas dataframe
Error in labelling the name of the columns using pandas dataframe

Time:09-30

I have an array of data of (31,1)

df

array([-4.92986060e-01, -3.26816435e-01, -2.81509125e-02, -5.50369198e-02,
   -4.78291735e-01, -3.77629735e-01,  2.56439110e-01, -7.80681558e-02,
    1.16469866e-01,  3.85537902e-02,  1.45576290e-02,  1.30638731e-01,
   -1.38000533e-01,  1.59521248e-02, -5.90236009e 00, -1.93493371e 00,
    9.29390668e-02,  1.58132616e-01, -2.37706974e-01,  4.10766116e-01,
   -1.99106536e-02,  2.91439759e-03, -1.34659982e 00, -8.83233098e-02,
   -1.19043573e-01, -1.98791078e-02,  2.18003752e-03,  7.97191732e-03,
    5.01870085e-02,  8.15185865e-02,  3.56969073e-02])

I am trying to label each value with its header by using pd.dataframe

df = pd.DataFrame (df,  columns=[feature_names])

but it shows that the data dimensions I was trying to imply is (31,31)

ValueError: Shape of passed values is (31, 1), indices imply (31, 31)

CodePudding user response:

Just make it a list

df = pd.DataFrame ([df],  columns=[feature_names])
  • Related