now :
inputs.values[:2]
Out[12]: array(['[24,28]', '[8,15,9]'], dtype=object)
i want to get numpy 2D array like this
[[1,2,3],[2,3,4]]
how to transform ?
now :
inputs.values[:2]
Out[12]: array(['[24,28]', '[8,15,9]'], dtype=object)
i want to get numpy 2D array like this
[[1,2,3],[2,3,4]]
how to transform ?
 
    
    You can use literal_eval() and tolist() as below:
import pandas as pd 
import ast
import numpy as np
inputs = pd.Series(['[11, 21, 8]', '[18, 65, 108]'])
converted_inputs=np.array([ast.literal_eval(row) for row in inputs.tolist()])
print("converted_inputs=\n",converted_inputs)
The output is:
converted_inputs=
 [[ 11  21   8]
 [ 18  65 108]]
