0

I have a Pandas Series containing 1D arrays/lists. I want to extract it to a 2D NumPy array.

s=pd.Series([[1,2,3,4],[5,6,7,8]])

With to_numpy() I get a 1D array looking like this

array([list([1, 2, 3, 4]), list([5, 6, 7, 8])], dtype=object)

However, I want something like array([[1,2,3,4],[5,6,7,8]]).

1 Answer 1

1

Convert first to lists and then to array:

arr = np.array(s.tolist())
print (arr)
[[1 2 3 4]
 [5 6 7 8]]
Sign up to request clarification or add additional context in comments.

1 Comment

Hello meanwhile i have found a solution anyways:) i used np.array([*s.array])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.