python - Numpy nd array to pandas column without [] -


i'm trying transform numpy nd array pandas column, data coming brackets.

this np array:

array([[[  7.10105920e+07],         [  9.18736320e+07],         [  8.35562800e+07],         [  7.16590640e+07],         [  8.28060960e+07],         [  6.77042000e+07],         [  7.07195360e+07],         [  1.04754616e+08],         [  7.27420400e+07],         [  7.33461760e+07],         [  6.34156040e+07],         [  8.00440800e+07], 

this how i'm sending dataframe:

predictions = pd.dataframe() predictions['y_test'] = y_test[0].tolist() 

this i'm getting:

           y_test 0    [71010592.0] 1    [91873632.0] 2    [83556280.0] 3    [71659064.0] 4    [82806096.0] 5    [67704200.0] 6    [70719536.0] 7   [104754616.0] 8    [72742040.0] 9    [73346176.0] 

how can remove brackets ([])?

it looks 3d array. can pass first element dataframe constructor:

pd.dataframe(y_test[0], columns=['y_test']) out:           y_test 0    71010592.0 1    91873632.0 2    83556280.0 3    71659064.0 4    82806096.0 5    67704200.0 6    70719536.0 7   104754616.0 8    72742040.0 9    73346176.0 10   63415604.0 11   80044080.0 

a better alternative divakar use squeeze:

pd.dataframe(arr.squeeze(), columns=['y_test']) out:           y_test 0    71010592.0 1    91873632.0 2    83556280.0 3    71659064.0 4    82806096.0 5    67704200.0 6    70719536.0 7   104754616.0 8    72742040.0 9    73346176.0 10   63415604.0 11   80044080.0 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -