2

Consider the following code:

import numpy as np
import pandas as pd

a = np.array([[1,2],[3,4],[5,6],[7,8]])
k = pd.DataFrame({"a": list(a)})

df

I'd like to retrieve the original numpy array. However, when I call .values I get something different.

values

How can I get the original numpy array, that looks like this:

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

?
Thank you.

1 Answer 1

2

You can create nested lists and convert to 2d array:

np.array(k['a'].tolist())
Sign up to request clarification or add additional context in comments.

Comments

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.