[Python] How to convert a pandas column that contains numpy arrays to nd array

Discussão em 'Python' iniciado por Stack, Agosto 5, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following dataframe :

    df = pd.DataFrame(
    {'a':[np.array([1,2,3]),np.array([4,5,6])]
    }
    )


    i want to have a numpy array like following extracted from the a column:

    array([[1., 2., 3.],
    [4., 5., 6.]])


    i can do it like below:

    for i, row in df.iterrows():
    t_arr[i,:] = row["a"]


    but i am looking for a solution without for loop. .values and to_numpy() don't return the desired results

    Continue reading...

Compartilhe esta Página