0

I ended up with the following data structure:

import numpy as np
import pandas as pd

my_df = pd.DataFrame({'col_1': [1,2,3]})
my_df['col_1'] = my_df['col_1'].apply(lambda x: np.array([1,2,3]))
my_df.as_matrix()

it looks like this:

array([[array([1, 2, 3])],
       [array([1, 2, 3])],
       [array([1, 2, 3])]], dtype=object)

Whily I would like it to look like simply numpy matrix. Any thoughts?

1 Answer 1

2

If you just want an array, you can

np.array(my_df.col_1.tolist())

array([[1, 2, 3],
       [1, 2, 3],
       [1, 2, 3]])
Sign up to request clarification or add additional context in comments.

1 Comment

Is it possible to apply it to multiple columns at once?

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.