-1

I have a pandas Series which contains 2d (?) numpy ndarrays of the same length with the shape (1 ,208), what would be the easiest way to make it into pandas dataframe with 208 columns?

how it looks like

When i tried to make a numpy array, it turned out to be 3D, though I expected it to be 2D

x = []
for i in train_rdkit_desc:
    np.reshape(i, 208)
    x.append(i)

x = np.array(x)
x.shape
    
    (908, 1, 208)
2
  • stackoverflow.com/questions/32594136/…. pd.DataFrame(series_to_convert.map(lambda x: x[0]).tolist()) Commented Dec 3, 2021 at 22:27
  • np.reshape(i, 208) does not work in-place. Commented Dec 4, 2021 at 1:13

1 Answer 1

1

I think the easiest way:

you can create a list with the name of your numpy arrays. After that use method concatanation by columns (axis = 1):

df3 = pd.concat([numpy1,numpy2,..., numpyn], axis = 1)

Example:

a = np.array([1, 2, 3, 4, 5, 6])
b = np.array([2, 2, 3, 4, 5, 6])
df= pd.concat([pd.DataFrame(a), pd.DataFrame(b)])
   
Sign up to request clarification or add additional context in comments.

3 Comments

this way doesn't work, i get a 1-column dataframe with ndarrays
Do you need 2D array with same vectors?
I changed my answer...

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.